Shutting down cleanly
Ensure your app shuts down cleanly when terminated
Example handling SIGINT
import { Bus, BusInstance } from '@node-ts/bus-core'
let bus: BusInstance
const start = async () => {
bus = Bus.configure().initialize()
await bus.start()
}
/**
* Listens for a signal interrupt and gracefully disposes the bus
* before exiting.
*/
const listenForSigInt = () => {
process.once('SIGINT', async () => {
console.log('Received SIGINT, shutting down...')
if (bus) {
await bus.dispose()
}
})
}
listenForSigInt()
start().catch(console.err)Last updated