mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
The explicit goal is to let users use `import.meta.url` to re-load thecurrent module inside a Worker instance. Fixes: https://github.com/nodejs/node/issues/30780 PR-URL: https://github.com/nodejs/node/pull/31664 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
19 lines
468 B
JavaScript
19 lines
468 B
JavaScript
import { mustCall } from '../common/index.mjs';
|
|
import assert from 'assert';
|
|
import { Worker, isMainThread, parentPort } from 'worker_threads';
|
|
|
|
const TEST_STRING = 'Hello, world!';
|
|
|
|
if (isMainThread) {
|
|
const w = new Worker(new URL(import.meta.url));
|
|
w.on('message', mustCall((message) => {
|
|
assert.strictEqual(message, TEST_STRING);
|
|
}));
|
|
} else {
|
|
setImmediate(() => {
|
|
process.nextTick(() => {
|
|
parentPort.postMessage(TEST_STRING);
|
|
});
|
|
});
|
|
}
|