closeout/exit-hook
Every export of closeout/exit-hook, with its signature and doc comment: asyncExitHook, gracefulExit, exitHook, plus 3 types.
import exitHook from 'closeout/exit-hook';
import { asyncExitHook, gracefulExit } from 'closeout/exit-hook';Functions
default
The default export, declared as exitHook.
Register a synchronous hook. Returns the function that unregisters it.
Declared here and exported at the foot of the file: exit-hook's default is its
exitHook, so an import exitHook from 'closeout/exit-hook' swap only works if ours is a
default too, and this repository's lint wants every export last and grouped.
function exitHook(onExit: ExitHookCallback): () => void;| Parameter | Type |
|---|---|
onExit | ExitHookCallback |
Returns () => void
asyncExitHook
Register an asynchronous hook, bounded by wait.
wait is required and must be a positive number: asyncExitHook(fn, {}) and
asyncExitHook(fn, { wait: 'abc' }) both throw, and both are graded.
function asyncExitHook(onExit: ExitHookCallback, options?: Partial<AsyncExitHookOptions>): () => void;| Parameter | Type |
|---|---|
onExit | ExitHookCallback |
options (optional) | Partial<AsyncExitHookOptions> |
Returns () => void
gracefulExit
Exit the way process.exit() cannot: asynchronous hooks get to run, and stdio is drained
before the process goes.
The argument is the exit code, and it is named signal upstream. Kept as upstream names
it, because a drop-in whose parameter names disagree with the incumbent's .d.ts is a
drop-in that breaks the first person to use a named argument in their editor.
function gracefulExit(signal?: number): void;| Parameter | Type |
|---|---|
signal (optional) | number |
Returns void
Interfaces
AsyncExitHookOptions
interface AsyncExitHookOptions {
/**
* How long this hook may take, in milliseconds. Required and positive — `exit-hook` throws
* on a missing or non-numeric value and its `type enforcing` case asserts both.
*/
wait: number;
}Types
ExitHookCallback
A hook takes the code the process is about to leave with.
type ExitHookCallback = (exitCode: number | string) => unknown;Options
type Options = AsyncExitHookOptions;