1'use strict'; 2const common = require('../common'); 3const assert = require('assert'); 4const { Worker } = require('worker_threads'); 5 6// Test that calling worker.terminate() if kHandler is null should return an 7// empty promise that resolves to undefined, even when a callback is passed 8 9const worker = new Worker(` 10const { parentPort } = require('worker_threads'); 11parentPort.postMessage({ hello: 'world' }); 12`, { eval: true }); 13 14process.once('beforeExit', common.mustCall(() => worker.ref())); 15 16worker.on('exit', common.mustCall(() => { 17 worker.terminate().then((res) => assert.strictEqual(res, undefined)); 18 worker.terminate(() => null).then( 19 (res) => assert.strictEqual(res, undefined) 20 ); 21})); 22 23worker.unref(); 24