Skip to content

Commit 29dc3fd

Browse files
committed
worker: have terminate return a promise.
See: nodejs/node#28021
1 parent 2a9c61e commit 29dc3fd

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/browser/worker.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,14 +262,19 @@ class Worker extends EventEmitter {
262262
});
263263
}
264264

265-
terminate(callback) {
265+
async terminate(callback) {
266266
if (this._exited)
267267
return;
268268

269269
if (typeof callback === 'function')
270270
this.once('exit', code => callback(null, code));
271271

272272
this._terminate(1);
273+
274+
// See: https://github.com/nodejs/node/pull/28021
275+
return new Promise((resolve) => {
276+
this.once('exit', resolve);
277+
});
273278
}
274279

275280
unref() {

lib/process/worker.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,14 +638,19 @@ class Worker extends EventEmitter {
638638
this._exited = true;
639639
}
640640

641-
terminate(callback) {
641+
async terminate(callback) {
642642
if (this._exited)
643643
return;
644644

645645
if (typeof callback === 'function')
646646
this.once('exit', code => callback(null, code));
647647

648648
this._terminate(1);
649+
650+
// See: https://github.com/nodejs/node/pull/28021
651+
return new Promise((resolve) => {
652+
this.once('exit', resolve);
653+
});
649654
}
650655

651656
unref() {

0 commit comments

Comments
 (0)