web 3d图形渲染器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.2 KiB

  1. # capture-exit
  2. [![Build status](https://ci.appveyor.com/api/projects/status/8044m918rwic8b9n/branch/master?svg=true)](https://ci.appveyor.com/project/embercli/capture-exit/branch/master)
  3. [![Build Status](https://travis-ci.org/ember-cli/capture-exit.svg?branch=master)](https://travis-ci.org/ember-cli/capture-exit)
  4. Allow cooprative async exit handlers, we unfortunately must hijack
  5. process.exit.
  6. It allows a handler to ensure exit, without that exit handler impeding other
  7. similar handlers
  8. for example, see: [sindresorhus/ora#27](https://github.com/sindresorhus/ora/issues/27)
  9. Differences between `process.on('exit')` and `captureExit.onExit(...)` => https://github.com/ember-cli/capture-exit/issues/12
  10. ### Installation
  11. ```sh
  12. yarn add capture-exit
  13. // or
  14. npm install --save capture-exit
  15. ```
  16. ### Usage
  17. ```js
  18. // as early in startup as possible
  19. require('capture-exit').captureExit();
  20. // when you want to schedule some work on exit:
  21. function onExit() {
  22. return something.processWillExit(); // you can return promises, which will pause exit until fulfilled
  23. }
  24. require('capture-exit').onExit(onExit); // add an exit handler
  25. require('capture-exit').offExit(onExit); // allows one to remove an exit handle if it is not longer required
  26. ```