catch-exit
Version:
Catch Node.js exit conditions, including errors and unhandled rejections.
53 lines (52 loc) • 1.99 kB
TypeScript
/**
* Add a callback function to be called upon process exit or death.
*
* @category Main
* @returns The callback itself for chaining purposes.
*/
export declare function addExitCallback(
/**
* Typed to block async functions. Async functions will not work for 'exit' events, triggered
* from process.exit(), but will work with other events this catches. If you wish to perform
* async functions have this callback call an async function but remember it won't be awaited if
* the signal is 'exit'.
*/
callback: ExitCallback): ExitCallback;
/**
* Remove the given callback function from the set of previously added exit callbacks.
*
* @category Main
* @returns `true` if the callback was found and removed. `false` otherwise.
*/
export declare function removeExitCallback(
/** The exact callback (by reference) to remove, previously added by {@link addExitCallback}. */
callback: ExitCallback): boolean;
/**
* If this callback is async, it won't actually complete or be awaited in some cases, like when
* calling `process.exit()`.
*
* @category Internal
*/
export type ExitCallback = (signal: CatchSignals, exitCode?: number, error?: Error) => void | Promise<void>;
/**
* Signals listened to by this package.
*
* @category Internal
*/
export declare const interceptedSignals: readonly ["SIGHUP", "SIGINT", "SIGTERM", "SIGQUIT"];
/**
* Signals that may be passed to {@link ExitCallback} as its `signal` argument.
* `'unhandledRejection'` is not a part of this because those are all turned into
* `'uncaughtException'` errors.
*
* @category Internal
*/
export declare const catchSignalStrings: readonly ["SIGHUP", "SIGINT", "SIGTERM", "SIGQUIT", "exit", "uncaughtException"];
/**
* Signals that may be passed to {@link ExitCallback} as its `signal` argument.
* `'unhandledRejection'` is not a part of this because those are all turned into
* `'uncaughtException'` errors.
*
* @category Internal
*/
export type CatchSignals = (typeof catchSignalStrings)[number];