UNPKG

1.33 kBTypeScriptView Raw
1/**
2 * CleanKill hooks the interrupt handler, and provides callbacks for your code
3 * to cleanly shut down before the process exits.
4 */
5/**
6 * The type of a cleankill interrupt handler.
7 */
8export declare type Handler = () => Promise<void>;
9/**
10 * Register a handler to occur on SIGINT. The handler must return a promise if
11 * it has any asynchronous work to do. The process will be terminated once
12 * all handlers complete. If a handler throws or the promise it returns rejects
13 * then the process will be terminated immediately.
14 */
15export declare function onInterrupt(handler: Handler): void;
16/**
17 * Waits for all promises to settle, then rejects with the first error, if any.
18 */
19export declare function promiseAllStrict(promises: Promise<any>[]): Promise<void>;
20/**
21 * Call all interrupt handlers, and call the callback when they all complete.
22 *
23 * Clears the list of interrupt handlers.
24 */
25export declare function close(): Promise<void>;
26/**
27 * Calls all interrupt handlers, then exits with exit code 0.
28 *
29 * If called more than once it skips waiting for the interrupt handlers to
30 * finish and exits with exit code 1. If there are any errors with interrupt
31 * handlers, the process exits immediately with exit code 2.
32 *
33 * This function is called when a SIGINT is received.
34 */
35export declare function interrupt(): void;