summaryrefslogtreecommitdiff
path: root/test/parallel/test-worker-terminate-microtask-loop.js
blob: b2351c5d0bb0511f4d7f89554fd2f535a5d7657b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
'use strict';
const common = require('../common');
const assert = require('assert');
const { Worker } = require('worker_threads');

// Verify that `.terminate()` interrupts the microtask queue.

const worker = new Worker(`
function loop() { Promise.resolve().then(loop); } loop();
require('worker_threads').parentPort.postMessage('up');
`, { eval: true });

worker.once('message', common.mustCall(() => {
  setImmediate(() => worker.terminate());
}));

worker.once('exit', common.mustCall((code) => {
  assert.strictEqual(code, 1);
}));