An open API service indexing awesome lists of open source software.

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: 6 months ago
JSON representation

Execute a function right before the process is about to exit.

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