UNPKG

1.62 kBTypeScriptView Raw
1import type { AbortSignalWithReason, TaskResult } from './types';
2/**
3 * Synchronously raises {@link TaskAbortError} if the task tied to the input `signal` has been cancelled.
4 * @param signal
5 * @param reason
6 * @see {TaskAbortError}
7 */
8export declare const validateActive: (signal: AbortSignal) => void;
9/**
10 * Generates a race between the promise(s) and the AbortSignal
11 * This avoids `Promise.race()`-related memory leaks:
12 * https://github.com/nodejs/node/issues/17469#issuecomment-349794909
13 */
14export declare function raceWithSignal<T>(signal: AbortSignalWithReason<string>, promise: Promise<T>): Promise<T>;
15/**
16 * Runs a task and returns promise that resolves to {@link TaskResult}.
17 * Second argument is an optional `cleanUp` function that always runs after task.
18 *
19 * **Note:** `runTask` runs the executor in the next microtask.
20 * @returns
21 */
22export declare const runTask: <T>(task: () => Promise<T>, cleanUp?: (() => void) | undefined) => Promise<TaskResult<T>>;
23/**
24 * Given an input `AbortSignal` and a promise returns another promise that resolves
25 * as soon the input promise is provided or rejects as soon as
26 * `AbortSignal.abort` is `true`.
27 * @param signal
28 * @returns
29 */
30export declare const createPause: <T>(signal: AbortSignal) => (promise: Promise<T>) => Promise<T>;
31/**
32 * Given an input `AbortSignal` and `timeoutMs` returns a promise that resolves
33 * after `timeoutMs` or rejects as soon as `AbortSignal.abort` is `true`.
34 * @param signal
35 * @returns
36 */
37export declare const createDelay: (signal: AbortSignal) => (timeoutMs: number) => Promise<void>;