omniwheel
Version:
Boilerplate reduction for backend and microservices. Scale your application easily in any direction.
15 lines (14 loc) • 799 B
TypeScript
/// <reference types="node" />
export type TerminationCallback = (signal: NodeJS.Signals) => (void | Promise<void>);
/**
* Register a callback for when termination of the process is requested via an external signal. When a signal is
* received, all callbacks will be run serially in reverse order, and then the process will exit.
* Explicit termination such as via process.exit() will not invoke any of the callbacks.
*
* The callback can be asynchronous, returning a Promise. Still it is required to limit the total amount of time spent
* in termination callbacks, since the OS (or container orchestration) might forcefully kill the process a few seconds
* after the signal.
*
* @param fn The callback to register.
*/
export declare function onTermination(fn: TerminationCallback): void;