Name |
Date |
Size |
#Lines |
LOC |
||
---|---|---|---|---|---|---|
.. | - | - | ||||
CHANGELOG.md | D | 12-May-2024 | 1 KiB | 28 | 13 | |
LICENSE.txt | D | 12-May-2024 | 748 | 17 | 13 | |
README.md | D | 12-May-2024 | 1.5 KiB | 41 | 28 | |
index.js | D | 12-May-2024 | 3.8 KiB | 158 | 114 | |
package.json | D | 12-May-2024 | 1.8 KiB | 73 | 72 | |
signals.js | D | 12-May-2024 | 1.3 KiB | 54 | 28 |
README.md
1# signal-exit 2 3[](https://travis-ci.org/tapjs/signal-exit) 4[](https://coveralls.io/r/tapjs/signal-exit?branch=master) 5[](https://www.npmjs.com/package/signal-exit) 6[](https://ci.appveyor.com/project/bcoe/signal-exit) 7[](https://github.com/conventional-changelog/standard-version) 8 9When you want to fire an event no matter how a process exits: 10 11* reaching the end of execution. 12* explicitly having `process.exit(code)` called. 13* having `process.kill(pid, sig)` called. 14* receiving a fatal signal from outside the process 15 16Use `signal-exit`. 17 18```js 19var onExit = require('signal-exit') 20 21onExit(function (code, signal) { 22 console.log('process exited!') 23}) 24``` 25 26## API 27 28`var remove = onExit(function (code, signal) {}, options)` 29 30The return value of the function is a function that will remove the 31handler. 32 33Note that the function *only* fires for signals if the signal would 34cause the proces to exit. That is, there are no other listeners, and 35it is a fatal signal. 36 37## Options 38 39* `alwaysLast`: Run this handler after any other signal or exit 40 handlers. This causes `process.emit` to be monkeypatched. 41