Skip to content

Commit 27f9bf2

Browse files
committed
Signal handling: Allow worker.terminate() to be synchronous
This also suppresses any synchronous exceptions thrown by `worker.terminate()`.
1 parent 26b0141 commit 27f9bf2

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/master/implementation.node.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ interface Terminable {
3232

3333
// Terminates the workers, empties the workers array, and exits.
3434
const onSignal = (workers: Terminable[], signal: string) => {
35-
Promise.all(workers.map(worker => worker.terminate())).then(
35+
// worker.terminate() might return a Promise or might be synchronous. This async helper function
36+
// creates a consistent interface.
37+
const terminate = async (worker: Terminable) => worker.terminate()
38+
Promise.all(workers.map(worker => terminate(worker))).then(
3639
() => process.exit(1),
3740
() => process.exit(1),
3841
)

0 commit comments

Comments
 (0)