when-exit
TypeScript icon, indicating that this package has built-in type declarations

2.1.4 • Public • Published

WhenExit

Execute a function right before the process, or the browser's tab, is about to exit.

Install

npm install when-exit

Usage

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

Package Sidebar

Install

npm i when-exit

Weekly Downloads

877,694

Version

2.1.4

License

MIT

Unpacked Size

6.9 kB

Total Files

17

Last publish

Collaborators

  • fabiospampinato