mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
9e84a26cb3
This addresses review comments from https://github.com/nodejs/node/pull/25871. Refs: https://github.com/nodejs/node/pull/25871 PR-URL: https://github.com/nodejs/node/pull/26017 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
35 lines
760 B
JavaScript
35 lines
760 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
|
const { Worker, isMainThread } = require('worker_threads');
|
|
|
|
if (isMainThread) {
|
|
const w = new Worker(__filename, {
|
|
stdin: true,
|
|
stdout: true,
|
|
stderr: true
|
|
});
|
|
|
|
const { stdin, stdout, stderr } = w;
|
|
|
|
w.on('exit', common.mustCall((code) => {
|
|
assert.strictEqual(code, 0);
|
|
|
|
// `postMessage` should not throw after termination
|
|
// (this mimics the browser behavior).
|
|
w.postMessage('foobar');
|
|
w.ref();
|
|
w.unref();
|
|
|
|
// Sanity check.
|
|
assert.strictEqual(w.threadId, -1);
|
|
assert.strictEqual(w.stdin, stdin);
|
|
assert.strictEqual(w.stdout, stdout);
|
|
assert.strictEqual(w.stderr, stderr);
|
|
}));
|
|
} else {
|
|
process.exit(0);
|
|
}
|