Skip to content

Commit

Permalink
worker: have terminate return a promise.
Browse files Browse the repository at this point in the history
  • Loading branch information
chjj committed Jun 11, 2019
1 parent 2a9c61e commit 29dc3fd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/browser/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,19 @@ class Worker extends EventEmitter {
});
}

terminate(callback) {
async terminate(callback) {
if (this._exited)
return;

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

this._terminate(1);

// See: https://github.com/nodejs/node/pull/28021
return new Promise((resolve) => {
this.once('exit', resolve);
});
}

unref() {
Expand Down
7 changes: 6 additions & 1 deletion lib/process/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -638,14 +638,19 @@ class Worker extends EventEmitter {
this._exited = true;
}

terminate(callback) {
async terminate(callback) {
if (this._exited)
return;

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

this._terminate(1);

// See: https://github.com/nodejs/node/pull/28021
return new Promise((resolve) => {
this.once('exit', resolve);
});
}

unref() {
Expand Down

0 comments on commit 29dc3fd

Please sign in to comment.