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

// Test that calling .terminate() during a timer callback works fine.

for (const fn of ['setTimeout', 'setImmediate', 'setInterval']) {
  const worker = new Worker(`
  const { parentPort } = require('worker_threads');
  ${fn}(() => {
    require('worker_threads').parentPort.postMessage({});
    while (true);
  });`, { eval: true });

  worker.on('message', common.mustCallAtLeast(() => {
    worker.terminate();
  }));
}