Intro

一个高阶函数,可以通过AbortSignal中止异步任务或在超时时自动中止。

A higher-order function that can abort asynchronous tasks by AbortSignal or automatically abort on timeout.

Demo

Types

export declare class AbortError extends Error {
}
export declare class TimeoutError extends Error {
}
export declare type AbortableOption = {
    timeout?: number;
    signal?: AbortSignal;
    alwaysPendingWhenAborted?: boolean;
};
export declare function abortableAsync<T, P extends any[], R>(fn: (this: T, ...p: P) => Promise<R>, opt?: AbortableOption): (this: T, ...p: P) => Promise<R>;
1
2
3
4
5
6
7
8
9
10