Skip to content

Commit 383f5aa

Browse files
committed
Signal handling: Wait for all workers to terminate
The promise returned from `Promise.all()` immediately rejects if any of the underlying promises reject, even if some of the other promises have not yet settled. Catch each rejection to give the other promises an opportunity to resolve. `Promise.allSettled()` could be used instead, but that's a relatively new function that was added in Node.js v12.9.0.
1 parent 854f922 commit 383f5aa

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

Diff for: src/master/implementation.node.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ const onSignal = (workers: Terminable[], signal: string) => {
3636
// worker.terminate() might return a Promise or might be synchronous. This async helper function
3737
// creates a consistent interface.
3838
const terminate = async (worker: Terminable) => worker.terminate()
39-
Promise.all(workers.map(worker => terminate(worker))).then(
40-
() => process.exit(1),
41-
() => process.exit(1),
42-
)
39+
Promise.all(workers.map(worker => terminate(worker).catch(() => {}))).then(() => process.exit(1))
4340
workers.length = 0
4441
}
4542

Diff for: tslint.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
],
1313
"interface-over-type-literal": false,
1414
"member-ordering": false,
15+
"no-empty": [true, "allow-empty-functions"],
1516
"no-implicit-dependencies": [
1617
true,
1718
["tiny-worker", "worker_threads"]

0 commit comments

Comments
 (0)