const exitSignals = [ "SIGTERM" , "SIGINT" ] as NodeJS . Signals [ ] ; param cleanUpFunction export function onGracefulShutdown ( cleanUpFunction , logFn = console . log ) { for ( const signal of exitSignals ) { process . once ( signal , async function onSignal ( ) { logFn ( "Stopping gracefully, use Ctrl+C again to force process exit" ) ; process . on ( signal , function onSecondSignal ( ) { logFn ( "Forcing process exit" ) ; process . exit ( 1 ) ; } ) ; await cleanUpFunction ( ) ; } ) ; } }