https://github.com/ember-cli/capture-exit
https://github.com/ember-cli/capture-exit
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/ember-cli/capture-exit
- Owner: ember-cli
- License: mit
- Created: 2016-11-09T19:56:25.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2025-03-06T10:50:09.000Z (11 months ago)
- Last Synced: 2025-08-29T22:49:48.444Z (5 months ago)
- Language: JavaScript
- Size: 110 KB
- Stars: 9
- Watchers: 8
- Forks: 7
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# capture-exit
[](https://ci.appveyor.com/project/embercli/capture-exit/branch/master)
[](https://travis-ci.org/ember-cli/capture-exit)
Allow cooprative async exit handlers, we unfortunately must hijack
process.exit.
It allows a handler to ensure exit, without that exit handler impeding other
similar handlers
for example, see: [sindresorhus/ora#27](https://github.com/sindresorhus/ora/issues/27)
Differences between `process.on('exit')` and `captureExit.onExit(...)` => https://github.com/ember-cli/capture-exit/issues/12
### Installation
```sh
yarn add capture-exit
// or
npm install --save capture-exit
```
### Usage
```js
// as early in startup as possible
require('capture-exit').captureExit();
// when you want to schedule some work on exit:
function onExit() {
return something.processWillExit(); // you can return promises, which will pause exit until fulfilled
}
require('capture-exit').onExit(onExit); // add an exit handler
require('capture-exit').offExit(onExit); // allows one to remove an exit handle if it is not longer required
```