mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
66a635cece
PR-URL: https://github.com/nodejs/node/pull/53682 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
35 lines
720 B
JavaScript
35 lines
720 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const {
|
|
parentPort,
|
|
postMessageToThread,
|
|
Worker,
|
|
workerData,
|
|
} = require('node:worker_threads');
|
|
const { rejects } = require('node:assert');
|
|
|
|
async function test() {
|
|
const worker = new Worker(__filename, { workerData: { children: true } });
|
|
|
|
await rejects(common.mustCall(function() {
|
|
return postMessageToThread(worker.threadId);
|
|
}), {
|
|
name: 'Error',
|
|
code: 'ERR_WORKER_MESSAGING_ERRORED',
|
|
});
|
|
|
|
worker.postMessage('success');
|
|
}
|
|
|
|
if (!workerData?.children) {
|
|
test();
|
|
} else {
|
|
process.on('workerMessage', () => {
|
|
throw new Error('KABOOM');
|
|
});
|
|
|
|
parentPort.postMessage('ready');
|
|
parentPort.once('message', common.mustCall());
|
|
}
|