nodejs/test/parallel/test-worker-terminate-null-handler.js
James M Snell 411cc42d22 worker: move terminate callback to end-of-life
Passing a callback to worker.terminate() has been deprecated
for about six years now. It's time to remove it.

PR-URL: https://github.com/nodejs/node/pull/58528
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
2025-06-02 11:16:49 -07:00

22 lines
632 B
JavaScript

'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 });
process.once('beforeExit', common.mustCall(() => worker.ref()));
worker.on('exit', common.mustCall(() => {
worker.terminate().then((res) => assert.strictEqual(res, undefined));
}));
worker.unref();