thread-stream
Advanced tools
Comparing version 0.9.0 to 0.10.0
14
index.js
@@ -131,2 +131,11 @@ 'use strict' | ||
break | ||
case 'ERROR': | ||
this.closed = true | ||
// TODO only remove our own | ||
this.worker.removeAllListeners('exit') | ||
this.worker.terminate().then(null, () => {}) | ||
process.nextTick(() => { | ||
this.emit('error', msg.err) | ||
}) | ||
break | ||
default: | ||
@@ -140,7 +149,6 @@ throw new Error('this should not happen: ' + msg.code) | ||
setImmediate(() => { | ||
if (code === 0) { | ||
this.emit('close') | ||
} else { | ||
if (code !== 0) { | ||
this.emit('error', new Error('The worker thread exited')) | ||
} | ||
this.emit('close') | ||
}) | ||
@@ -147,0 +155,0 @@ }) |
@@ -21,2 +21,9 @@ 'use strict' | ||
destination.on('error', function (err) { | ||
parentPort.postMessage({ | ||
code: 'ERROR', | ||
err | ||
}) | ||
}) | ||
destination.on('close', function () { | ||
@@ -86,5 +93,15 @@ // process._rawDebug('worker close emitted') | ||
process.on('unhandledRejection', function (err) { | ||
// TODO transfer this to main | ||
console.error(err) | ||
parentPort.postMessage({ | ||
code: 'ERROR', | ||
err | ||
}) | ||
process.exit(1) | ||
}) | ||
process.on('uncaughtException', function (err) { | ||
parentPort.postMessage({ | ||
code: 'ERROR', | ||
err | ||
}) | ||
process.exit(1) | ||
}) |
{ | ||
"name": "thread-stream", | ||
"version": "0.9.0", | ||
"version": "0.10.0", | ||
"description": "A streaming way to send data to a Node.js Worker Thread", | ||
@@ -10,3 +10,3 @@ "main": "index.js", | ||
"husky": "^6.0.0", | ||
"sonic-boom": "^1.3.2", | ||
"sonic-boom": "^2.0.1", | ||
"standard": "^16.0.3", | ||
@@ -13,0 +13,0 @@ "tap": "^15.0.0" |
@@ -89,3 +89,3 @@ 'use strict' | ||
const [err] = await once(stream, 'error') | ||
t.equal(err.message, 'The worker thread exited') | ||
t.equal(err.message, 'kaboom') | ||
@@ -106,1 +106,57 @@ try { | ||
}) | ||
test('emit error if worker stream emit error', async function (t) { | ||
const stream = new ThreadStream({ | ||
filename: join(__dirname, 'error.js'), | ||
sync: true | ||
}) | ||
stream.on('ready', function () { | ||
stream.write('hello world\n') | ||
}) | ||
const [err] = await once(stream, 'error') | ||
t.equal(err.message, 'kaboom') | ||
try { | ||
stream.write('noop') | ||
t.fail('unreacheable') | ||
} catch (err) { | ||
t.equal(err.message, 'the worker has exited') | ||
} | ||
try { | ||
stream.write('noop') | ||
t.fail('unreacheable') | ||
} catch (err) { | ||
t.equal(err.message, 'the worker has exited') | ||
} | ||
}) | ||
test('emit error if thread have uncaughtException', async function (t) { | ||
const stream = new ThreadStream({ | ||
filename: join(__dirname, 'uncaughtException.js'), | ||
sync: true | ||
}) | ||
stream.on('ready', function () { | ||
stream.write('hello world\n') | ||
}) | ||
const [err] = await once(stream, 'error') | ||
t.equal(err.message, 'kaboom') | ||
try { | ||
stream.write('noop') | ||
t.fail('unreacheable') | ||
} catch (err) { | ||
t.equal(err.message, 'the worker has exited') | ||
} | ||
try { | ||
stream.write('noop') | ||
t.fail('unreacheable') | ||
} catch (err) { | ||
t.equal(err.message, 'the worker has exited') | ||
} | ||
}) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39142
29
1286