mirror of https://gitee.com/openkylin/nodejs.git
20 lines
474 B
JavaScript
20 lines
474 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const { Worker, isMainThread, parentPort } = require('worker_threads');
|
|
|
|
const kTestString = 'Hello, world!';
|
|
|
|
if (isMainThread) {
|
|
const w = new Worker(__filename);
|
|
w.on('message', common.mustCall((message) => {
|
|
assert.strictEqual(message, kTestString);
|
|
}));
|
|
} else {
|
|
setImmediate(() => {
|
|
process.nextTick(() => {
|
|
parentPort.postMessage(kTestString);
|
|
});
|
|
});
|
|
}
|