https://github.com/fabiospampinato/when-exit
Execute a function right before the process is about to exit.
https://github.com/fabiospampinato/when-exit
catch event exit handle hook intercept signal
Last synced: about 1 year ago
JSON representation
Execute a function right before the process is about to exit.
- Host: GitHub
- URL: https://github.com/fabiospampinato/when-exit
- Owner: fabiospampinato
- License: mit
- Created: 2022-02-08T21:14:31.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2025-01-12T18:35:26.000Z (over 1 year ago)
- Last Synced: 2025-04-02T06:08:04.846Z (about 1 year ago)
- Topics: catch, event, exit, handle, hook, intercept, signal
- Language: TypeScript
- Homepage:
- Size: 16.6 KB
- Stars: 13
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# WhenExit
Execute a function right before the process, or the browser's tab, is about to exit.
## Install
```sh
npm install when-exit
```
## Usage
```ts
import whenExit from 'when-exit';
// Registering multiple callbacks
onExit ( () => {
console.log ( 'Callback 1' );
});
onExit ( () => {
console.log ( 'Callback 2' );
});
// Registering and disposing a callback
const disposer = onExit ( () => {
console.log ( 'Callback 3' );
});
disposer ();
// Triggering the process to exit
process.exit (); // Callback 1 and 2 are called before exiting
```
## License
MIT © Fabio Spampinato