index.d.ts 728 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. Run some code when the process exits.
  3. The `process.on('exit')` event doesn't catch all the ways a process can exit.
  4. This package is useful for cleaning up before exiting.
  5. @param callback - The callback to execute when the process exits.
  6. @returns A function that removes the hook when called.
  7. @example
  8. ```
  9. import exitHook = require('exit-hook');
  10. exitHook(() => {
  11. console.log('Exiting');
  12. });
  13. // You can add multiple hooks, even across files
  14. exitHook(() => {
  15. console.log('Exiting 2');
  16. });
  17. throw new Error('🦄');
  18. //=> 'Exiting'
  19. //=> 'Exiting 2'
  20. // Removing an exit hook:
  21. const unsubscribe = exitHook(() => {});
  22. unsubscribe();
  23. ```
  24. */
  25. declare function exitHook(callback: () => void): () => void;
  26. export = exitHook;