Function: gracefulExit()
gracefulExit(
exitCode, ...functions):void
Exit the process once cleanup functions have run. The call returns at once; on the next turn of the event loop (setImmediate) the functions are called one after the other, each awaited before the next, then process.exit() is called with the exit code. An error thrown or a promise rejected by a function is ignored and the next function still runs; a function whose promise never settles keeps the process from exiting.
Parameters
exitCode
number
The exit code of the process: 0 for a success, another integer for a failure.
functions
...(() => any)[]
The cleanup functions, synchronous or asynchronous, in the order they run; none exits directly.
Returns
void
Example
typescript
import {gracefulExit} from 'lakutata/utils'
declare function closeDatabase(): Promise<void>
process.once('SIGTERM', (): void => gracefulExit(0, closeDatabase, (): void => console.log('Bye')))