Skip to content

Commit

Permalink
feat: avoid registering duplicated handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
simonecorsi committed Jul 7, 2021
1 parent 54a26ce commit 30422b8
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ module.exports = function fine(
validateParameters(timeout, events, callbacks);

for (const event of events) {
if (process.listenerCount(event) > 0) {
throw new Error(`A ${event} handler is already registered`);
}
process.once(event, () => {
const code = event.match("^SIG") ? 0 : 1;
process.stdout.write(`[${event}] exiting with code ${code}\n`);
Expand Down

0 comments on commit 30422b8

Please sign in to comment.