worker: move terminate callback to end-of-life · nodejs/node@411cc42 · GitHub
Skip to content

Commit 411cc42

Browse files
committed
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: #58528 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
1 parent d33f4b5 commit 411cc42

4 files changed

Lines changed: 11 additions & 26 deletions

File tree

doc/api/deprecations.md

Lines changed: 4 additions & 1 deletion

lib/internal/worker.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const {
1111
ObjectEntries,
1212
Promise,
1313
PromiseResolve,
14+
PromiseWithResolvers,
1415
ReflectApply,
1516
RegExpPrototypeExec,
1617
SafeArrayIterator,
@@ -381,30 +382,21 @@ class Worker extends EventEmitter {
381382
ReflectApply(this[kPublicPort].postMessage, this[kPublicPort], args);
382383
}
383384

384-
terminate(callback) {
385+
terminate() {
385386
debug(`[${threadId}] terminates Worker with ID ${this.threadId}`);
386387

387388
this.ref();
388389

389-
if (typeof callback === 'function') {
390-
process.emitWarning(
391-
'Passing a callback to worker.terminate() is deprecated. ' +
392-
'It returns a Promise instead.',
393-
'DeprecationWarning', 'DEP0132');
394-
if (this[kHandle] === null) return PromiseResolve();
395-
this.once('exit', (exitCode) => callback(null, exitCode));
396-
}
397-
398390
if (this[kHandle] === null) return PromiseResolve();
399391

400392
this[kHandle].stopThread();
401393

402394
// Do not use events.once() here, because the 'exit' event will always be
403395
// emitted regardless of any errors, and the point is to only resolve
404396
// once the thread has actually stopped.
405-
return new Promise((resolve) => {
406-
this.once('exit', resolve);
407-
});
397+
const { promise, resolve } = PromiseWithResolvers();
398+
this.once('exit', resolve);
399+
return promise;
408400
}
409401

410402
async [SymbolAsyncDispose]() {

test/parallel/test-worker-nexttick-terminate.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@ process.nextTick(() => {
1212
});
1313
`, { eval: true });
1414

15-
// Test deprecation of .terminate() with callback.
16-
common.expectWarning(
17-
'DeprecationWarning',
18-
'Passing a callback to worker.terminate() is deprecated. ' +
19-
'It returns a Promise instead.', 'DEP0132');
20-
2115
w.on('message', common.mustCall(() => {
22-
setTimeout(() => {
23-
w.terminate(common.mustCall()).then(common.mustCall());
24-
}, 1);
16+
setTimeout(() => w.terminate().then(common.mustCall()), 1);
2517
}));

test/parallel/test-worker-terminate-null-handler.js

Lines changed: 1 addition & 3 deletions

0 commit comments

Comments
 (0)