From 339de34c3a23247ca458130eb842f0490d77472a Mon Sep 17 00:00:00 2001 From: Will White Date: Tue, 25 Jan 2011 14:54:21 -0500 Subject: [PATCH 1/3] Allow node path to be configured. --- lib/worker.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/worker.js b/lib/worker.js index a0a6390..3c8ddfd 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++; }; @@ -53,11 +53,12 @@ Worker.prototype.terminate = function () { 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); From d3f49e0281f659ce137d7b458b5ec50e13932f5f Mon Sep 17 00:00:00 2001 From: Will White Date: Tue, 25 Jan 2011 22:58:26 -0500 Subject: [PATCH 2/3] Fix termination of child processes. --- lib/worker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/worker.js b/lib/worker.js index 3c8ddfd..49dd3c6 100644 --- a/lib/worker.js +++ b/lib/worker.js @@ -142,7 +142,7 @@ WorkerChild.prototype = { }, terminate: function () { - this.child.stdin.end(); + this.child.kill(); } }; From 411300fc1bf38e27b71625cd8bbd181f6fa3cbb2 Mon Sep 17 00:00:00 2001 From: Will White Date: Wed, 26 Jan 2011 14:19:06 -0500 Subject: [PATCH 3/3] Fix terminate function and add kill function. --- lib/worker.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/worker.js b/lib/worker.js index 49dd3c6..b1405dc 100644 --- a/lib/worker.js +++ b/lib/worker.js @@ -50,6 +50,10 @@ Worker.prototype.postMessage = function (payload) { Worker.prototype.terminate = function () { this.impl.terminate(); }; + +Worker.prototype.kill = function () { + this.impl.kill(); +}; exports.Worker = Worker; @@ -142,6 +146,10 @@ WorkerChild.prototype = { }, terminate: function () { + this.child.stdin.end(); + }, + + kill: function () { this.child.kill(); } };