node/test/parallel/test-worker-safe-getters.js
Anna Henningsen 9e84a26cb3
worker: keep stdio after exit
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>
2019-02-12 01:17:13 +01:00

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);
}