UNPKG

2.34 kBTypeScriptView Raw
1/// <reference types="node" />
2export declare const ERROR_TIMEOUT_REACHED: Error;
3export declare function killProcessTree(pid: number, signal?: string | number): Promise<void>;
4/**
5 * Creates an alternative implementation of `process.env` object.
6 *
7 * On a Windows shell, `process.env` is a magic object that offers
8 * case-insensitive environment variable access. On other platforms, case
9 * sensitivity matters. This method creates an empty "`process.env`" object
10 * type that works for all platforms.
11 */
12export declare function createProcessEnv(...sources: {
13 [key: string]: string | undefined;
14}[]): NodeJS.ProcessEnv;
15/**
16 * Split a PATH string into path parts.
17 */
18export declare function getPathParts(envpath?: string): string[];
19/**
20 * Resolves when the given amount of milliseconds has passed.
21 */
22export declare function sleep(ms: number): Promise<void>;
23/**
24 * Resolves when a given predicate is true or a timeout is reached.
25 *
26 * Configure `interval` to set how often the `predicate` is called.
27 *
28 * By default, `timeout` is Infinity. If given a value (in ms), and that
29 * timeout value is reached, this function will reject with
30 * the `ERROR_TIMEOUT_REACHED` error.
31 */
32export declare function sleepUntil(predicate: () => boolean, { interval, timeout }: {
33 interval?: number;
34 timeout?: number;
35}): Promise<void>;
36/**
37 * Never resolves and keeps Node running.
38 */
39export declare function sleepForever(): Promise<never>;
40/**
41 * Register a synchronous function to be called once the process exits.
42 */
43export declare function onExit(fn: () => void): void;
44export declare type ExitFn = () => Promise<void>;
45/**
46 * Register an asynchronous function to be called when the process wants to
47 * exit.
48 *
49 * A handler will be registered for the 'SIGINT', 'SIGTERM', 'SIGHUP',
50 * 'SIGBREAK' signals. If any of the signal events is emitted, `fn` will be
51 * called exactly once, awaited upon, and then the process will exit once all
52 * registered functions are resolved.
53 */
54export declare function onBeforeExit(fn: ExitFn): void;
55/**
56 * Remove a function that was registered with `onBeforeExit`.
57 */
58export declare function offBeforeExit(fn: ExitFn): void;
59/**
60 * Asynchronous `process.exit()`, for running functions registered with
61 * `onBeforeExit`.
62 */
63export declare function processExit(exitCode?: number): Promise<void>;