Node.js process reload graceful
npm i @open-node/graceful --save
- your node.js process code
const Graceful = require('@open-node/graceful');
// defined loginfo handle function
const info = console.log
const graceful = Graceful(info);
// get process status, false when existing unless will be true
const status = graceful.enabled()
// regist callback when process exit
graceful.exit(() => {
// will be called when process exit
});
// wrap function, Once the function is executed, the process will not exit until the function is executed
const wrapped = graceful.runner(willBeWrappedFn);
wrapped(); // Once the function is executed, the process will not exit until the function is executed
// graceful.runnerAsync is the asynchronous version of runner
const wrapped = graceful.runner(willBeWrappedAsyncFn);
await wrapped(); // Once the function is executed, the process will not exit until the function is executed
infofunction log info output
Returns Tick Instance
regist event listenner for exiting
listennerfunction
Returns void
Wrap the function sync version. Once the be wrapped function is executed, the process will not exit until the function is executed
fnfunction will be wrapped fn
Returns function Be wrapped function
Wrap the function asynchronous version, Once the be wrapped function is executed, the process will not exit until the function is executed
fnAsyncFunction will be wrapped fn (asynchronous)
Returns function Be warpped function
The process status
Returns boolean status