blob: 69856659a5773be870b0cedf29b92f5bd5e566ec (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
'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);
}
|