mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
592f1845fa
PR-URL: https://github.com/nodejs/node/pull/41463 Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
28 lines
834 B
JavaScript
28 lines
834 B
JavaScript
'use strict';
|
||
const common = require('../common');
|
||
|
||
const { parentPort, MessageChannel, Worker } = require('worker_threads');
|
||
|
||
// Do not use isMainThread so that this test itself can be run inside a Worker.
|
||
if (!process.env.HAS_STARTED_WORKER) {
|
||
process.env.HAS_STARTED_WORKER = 1;
|
||
const w = new Worker(__filename);
|
||
w.once('message', common.mustCall(() => {
|
||
w.once('message', common.mustNotCall());
|
||
setTimeout(() => w.terminate(), 100);
|
||
}));
|
||
} else {
|
||
const { port1 } = new MessageChannel();
|
||
|
||
parentPort.postMessage('ready');
|
||
|
||
// Make sure we don’t end up running JS after the infinite loop is broken.
|
||
port1.postMessage({}, {
|
||
// eslint-disable-next-line require-yield
|
||
transfer: (function*() { while (true); })()
|
||
});
|
||
|
||
parentPort.postMessage('UNREACHABLE');
|
||
process.kill(process.pid, 'SIGINT');
|
||
}
|