A graceful way to shutdown / handle PRocess EXIT - way better than other *rexits
const prexit =
Here's a sample for shutting down an http server and database. First we stop the http server from accepting any new connections. Then we gracefully close the database connection to allow any pending queries to resolve.
Prexit is a simple function that takes a callback. This will be called with the signal and exit code / error on the following
beforeExit | uncaughtException | SIGTSTP | SIGQUIT | SIGHUP | SIGTERM | SIGINT
You can call prexit as many times as you'd like so you can do cleanup in the relevant places in your code. Prexit will await all promises that callbacks returns, and will ensure they are only called once. After all the promises finalizes prexit will call
prexit.ondone() which defaults to calling
You can also supply optional events to listen for as the first argument of prexit.