2018-06-26 18:31:36 +03:00
|
|
|
'use strict';
|
2019-05-12 15:11:13 +08:00
|
|
|
const common = require('../common');
|
2018-06-26 18:31:36 +03:00
|
|
|
const path = require('path');
|
|
|
|
const assert = require('assert');
|
|
|
|
const { Worker, isMainThread, parentPort } = require('worker_threads');
|
|
|
|
|
|
|
|
if (isMainThread) {
|
2020-03-29 09:52:44 -05:00
|
|
|
const w = new Worker(`./${path.relative('.', __filename)}`);
|
2018-06-26 18:31:36 +03:00
|
|
|
w.on('message', common.mustCall((message) => {
|
|
|
|
assert.strictEqual(message, 'Hello, world!');
|
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
parentPort.postMessage('Hello, world!');
|
|
|
|
}
|