node/test/parallel/test-worker.mjs
himself65 c2aedd0310
test: refactor test-worker
PR-URL: https://github.com/nodejs/node/pull/32509
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
2020-04-06 01:53:54 +02:00

19 lines
468 B
JavaScript

import { mustCall } from '../common/index.mjs';
import assert from 'assert';
import { Worker, isMainThread, parentPort } from 'worker_threads';
const kTestString = 'Hello, world!';
if (isMainThread) {
const w = new Worker(new URL(import.meta.url));
w.on('message', mustCall((message) => {
assert.strictEqual(message, kTestString);
}));
} else {
setImmediate(() => {
process.nextTick(() => {
parentPort.postMessage(kTestString);
});
});
}