世祺 0423d5801c Initial commit (by Create-Cloudflare CLI) | há 1 ano atrás | |
---|---|---|
.. | ||
index.d.ts | há 1 ano atrás | |
index.js | há 1 ano atrás | |
license | há 1 ano atrás | |
package.json | há 1 ano atrás | |
readme.md | há 1 ano atrás |
Run some code when the process exits
The process.on('exit')
event doesn't catch all the ways a process can exit.
This package is useful for cleaning up before exiting.
$ npm install exit-hook
const exitHook = require('exit-hook');
exitHook(() => {
console.log('Exiting');
});
// You can add multiple hooks, even across files
exitHook(() => {
console.log('Exiting 2');
});
throw new Error('🦄');
//=> 'Exiting'
//=> 'Exiting 2'
Removing an exit hook:
const exitHook = require('exit-hook');
const unsubscribe = exitHook(() => {});
unsubscribe();
Returns a function that removes the hook when called.
Type: Function
The callback to execute when the process exits.