node-worker-pool
Advanced tools
Comparing version 2.4.1 to 2.4.2
{ | ||
"name": "node-worker-pool", | ||
"version": "2.4.1", | ||
"version": "2.4.2", | ||
"dependencies": { | ||
@@ -16,3 +16,3 @@ "q": "~0.9.7" | ||
"devDependencies": { | ||
"jest-cli": "0.1.5" | ||
"jest-cli": "^0.1.18" | ||
}, | ||
@@ -19,0 +19,0 @@ "jest": { |
@@ -11,2 +11,3 @@ "use strict"; | ||
var child = child_process.spawn(workerPath, workerArgs); | ||
child.on('exit', this._onChildExit.bind(this)); | ||
child.stderr.setEncoding('utf8'); | ||
@@ -21,4 +22,7 @@ child.stderr.on('data', this._onStderr.bind(this)); | ||
this._pendingResponseDeferred = null; | ||
this._stderrData = ''; | ||
this._stdoutData = ''; | ||
this._streamParser = new JSONStreamParser(); | ||
this._workerArgs = workerArgs; | ||
this._workerPath = workerPath; | ||
@@ -59,3 +63,33 @@ // Send init data to the child first thing | ||
Worker.prototype._onChildExit = function(code, signalStr) { | ||
if (this._isDestroyed) { | ||
return; | ||
} | ||
var errorMsg = | ||
' exit code: ' + code + ', exit signal: ' + signalStr + '\n' + | ||
'stderr:\n' + | ||
' ' + this._stderrData.trim() + '\n' + | ||
'\n' + | ||
'stdout:\n' + | ||
' ' + this._stdoutData.trim(); | ||
if (this._initialized === false) { | ||
throw new Error( | ||
'Worker process exited before it could be initialized!' + | ||
errorMsg | ||
); | ||
} else if (this._pendingResponseDeferred !== null) { | ||
this._pendingResponseDeferred.reject(new Error( | ||
'Worker process exited before responding!' + | ||
errorMsg | ||
)); | ||
} | ||
// Try re-booting this worker | ||
Worker.call(this, this._workerPath, this._workerArgs, this._opts); | ||
}; | ||
Worker.prototype._onStderr = function(data) { | ||
this._stderrData += data; | ||
process.stderr.write(data); | ||
@@ -140,3 +174,3 @@ }; | ||
'Attempted to send a message to the worker before the response from ' + | ||
'the last message was received! Child processes can only handle one ' + | ||
'the last message was received! Worker processes can only handle one ' + | ||
'message at a time.' | ||
@@ -143,0 +177,0 @@ ); |
16302
398