node/test/parallel/test-worker.mjs
Guy Bedford 93226a5097
esm: unflag --experimental-modules
PR-URL: https://github.com/nodejs/node/pull/29866
Backport-PR-URL: https://github.com/nodejs/node/pull/33055
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
2020-05-13 17:52:54 +02:00

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