1'use strict';
2const common = require('../common');
3const { Worker } = require('worker_threads');
4
5// Test that calling .terminate() during a timer callback works fine.
6
7for (const fn of ['setTimeout', 'setImmediate', 'setInterval']) {
8  const worker = new Worker(`
9  const { parentPort } = require('worker_threads');
10  ${fn}(() => {
11    require('worker_threads').parentPort.postMessage({});
12    while (true);
13  });`, { eval: true });
14
15  worker.on('message', common.mustCallAtLeast(() => {
16    worker.terminate();
17  }));
18}
19