Skip to content

Instantly share code, notes, and snippets.

@raviagheda
Created September 15, 2022 16:08
Show Gist options
  • Save raviagheda/ec1a0a8dcda968768b58102c1d6a2009 to your computer and use it in GitHub Desktop.
Save raviagheda/ec1a0a8dcda968768b58102c1d6a2009 to your computer and use it in GitHub Desktop.
const signalTraps = ['SIGTERM', 'SIGINT', 'SIGUSR2'];

signalTraps.forEach(type => {
  process.once(type, async () => {
    try {
        console.log("On Exist");
        // perform operations here
        // await consumer.disconnect()
    } finally {
      process.kill(process.pid, type)
    }
  })
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment