Skip to content

Commit 9d5d0fa

Browse files
committed
Merge remote-tracking branch 'origin/pr/5' Allow path to node executable to be configured
cramforce#5 Note: merged using technqiue at https://gist.github.com/piscisaureus/3342247 since https://github.com/willwhite/node-worker no longer exists(?)
2 parents 35dd5c7 + 411300f commit 9d5d0fa

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

lib/worker.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var Worker = function (filename, impl, options) {
3737
});
3838

3939
if(!impl) impl = WorkerChild;
40-
this.impl = new impl(this, filename, options);
40+
this.impl = new impl(this, filename, options || {});
4141
this.workerIndex = workerIndex++;
4242
};
4343

@@ -50,14 +50,19 @@ Worker.prototype.postMessage = function (payload) {
5050
Worker.prototype.terminate = function () {
5151
this.impl.terminate();
5252
};
53+
54+
Worker.prototype.kill = function () {
55+
this.impl.kill();
56+
};
5357

5458
exports.Worker = Worker;
5559

56-
function WorkerChild (eventDest, filename) {
60+
function WorkerChild (eventDest, filename, options) {
5761
var self = this;
5862
this.eventDest = eventDest;
5963
this.filename = filename;
60-
this.child = child_process.spawn("node", [this.filename].concat(WORKER_PARAS));
64+
var nodePath = options.nodePath || "node";
65+
this.child = child_process.spawn(nodePath, [this.filename].concat(WORKER_PARAS));
6166
this.child.stdout.addListener("data", function (data) {
6267
debug("From worker " + data);
6368
self.handleData(data);
@@ -143,6 +148,10 @@ WorkerChild.prototype = {
143148

144149
terminate: function () {
145150
this.child.stdin.end();
151+
},
152+
153+
kill: function () {
154+
this.child.kill();
146155
}
147156
};
148157

0 commit comments

Comments
 (0)