Skip to content

Commit ac76cc3

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

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
@@ -33,7 +33,10 @@ interface Terminable {
3333

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

0 commit comments

Comments
 (0)