-
-
Notifications
You must be signed in to change notification settings - Fork 25
Open
Description
Bug
The following:
import { onExit } from 'signal-exit'
const cleanup = onExit(() => {
console.log('A')
cleanup()
})
onExit(() => {
console.log('B')
})Prints:
A
But should print:
A
B
Reason
When the exit is happening, signal-exit is iterating over the exit handlers here:
Line 107 in d8621bc
| for (const fn of this.listeners[ev]) { |
However, cleanup() ends up calling:
Line 93 in d8621bc
| list.splice(i, 1) |
Which directly mutates this.listeners. This makes the iteration above not work anymore, due to mutating an array while iterating on it. Instead, the following would work:
for (const fn of [...this.listeners[ev]]) {Metadata
Metadata
Assignees
Labels
No labels