summaryrefslogtreecommitdiff
path: root/test/parallel/test-worker-message-port-terminate-transfer-list.js
blob: a066405d9d14de7e7a9ebda48312c88cc815fb90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
'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({}, {
    transfer: (function*() { while (true); })()
  });

  parentPort.postMessage('UNREACHABLE');
  process.kill(process.pid, 'SIGINT');
}