closeout
API reference

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.

function exitHook(onExit: ExitHookCallback): () => void;
ParameterType
onExitExitHookCallback

Returns () => void

asyncExitHook

Register an asynchronous hook, bounded by wait.

function asyncExitHook(onExit: ExitHookCallback, options?: Partial<AsyncExitHookOptions>): () => void;
ParameterType
onExitExitHookCallback
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.

function gracefulExit(signal?: number): void;
ParameterType
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;

On this page