2020-02-06 16:08:07 +01:00
|
|
|
import { mustCall } from '../common/index.mjs';
|
|
|
|
import assert from 'assert';
|
|
|
|
import { Worker, isMainThread, parentPort } from 'worker_threads';
|
|
|
|
|
2020-03-27 00:46:10 +08:00
|
|
|
const kTestString = 'Hello, world!';
|
2020-02-06 16:08:07 +01:00
|
|
|
|
|
|
|
if (isMainThread) {
|
|
|
|
const w = new Worker(new URL(import.meta.url));
|
|
|
|
w.on('message', mustCall((message) => {
|
2020-03-27 00:46:10 +08:00
|
|
|
assert.strictEqual(message, kTestString);
|
2020-02-06 16:08:07 +01:00
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
setImmediate(() => {
|
|
|
|
process.nextTick(() => {
|
2020-03-27 00:46:10 +08:00
|
|
|
parentPort.postMessage(kTestString);
|
2020-02-06 16:08:07 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|