diff --git a/lib/worker.js b/lib/worker.js index a0a6390..b1405dc 100644 --- a/lib/worker.js +++ b/lib/worker.js @@ -37,7 +37,7 @@ var Worker = function (filename, impl, options) { }); if(!impl) impl = WorkerChild; - this.impl = new impl(this, filename, options); + this.impl = new impl(this, filename, options || {}); this.workerIndex = workerIndex++; }; @@ -50,14 +50,19 @@ Worker.prototype.postMessage = function (payload) { Worker.prototype.terminate = function () { this.impl.terminate(); }; + +Worker.prototype.kill = function () { + this.impl.kill(); +}; exports.Worker = Worker; -function WorkerChild (eventDest, filename) { +function WorkerChild (eventDest, filename, options) { var self = this; this.eventDest = eventDest; this.filename = filename; - this.child = child_process.spawn("node", [this.filename].concat(WORKER_PARAS)); + var nodePath = options.nodePath || "node"; + this.child = child_process.spawn(nodePath, [this.filename].concat(WORKER_PARAS)); this.child.stdout.addListener("data", function (data) { debug("From worker " + data); self.handleData(data); @@ -142,6 +147,10 @@ WorkerChild.prototype = { terminate: function () { this.child.stdin.end(); + }, + + kill: function () { + this.child.kill(); } };