2019-06-21 17:21:43 -05:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
const { Worker } = require('worker_threads');
|
|
|
|
|
|
|
|
// Test that calling worker.terminate() if kHandler is null should return an
|
|
|
|
// empty promise that resolves to undefined, even when a callback is passed
|
|
|
|
|
|
|
|
const worker = new Worker(`
|
|
|
|
const { parentPort } = require('worker_threads');
|
|
|
|
parentPort.postMessage({ hello: 'world' });
|
|
|
|
`, { eval: true });
|
|
|
|
|
2020-03-28 22:52:58 -05:00
|
|
|
process.once('beforeExit', common.mustCall(() => worker.ref()));
|
2019-06-21 17:21:43 -05:00
|
|
|
|
|
|
|
worker.on('exit', common.mustCall(() => {
|
|
|
|
worker.terminate().then((res) => assert.strictEqual(res, undefined));
|
2025-05-31 09:25:57 -07:00
|
|
|
|
2019-06-21 17:21:43 -05:00
|
|
|
}));
|
|
|
|
|
|
|
|
worker.unref();
|