/** Cancellation Token */ export interface CancelToken { /** Has it been cancelled or whether cancellation has been requested */ readonly cancelled: boolean; /** Communicates a request for cancellation */ cancel(): void; /** If cancelled, throw `CancelGuard` */ guard(): void; /** Register an event that will be triggered when cancelled */ reg(f: () => void): void; /** Waiting for cancellation */ reg(): Promise; /** Unregister event */ unReg(f: () => void): void; } /** Cancel Guard */ export declare class CancelGuard { #private; private constructor(); is(source: CancelToken): boolean; static new(source: CancelToken): CancelGuard; } /** Sync cancelable */ export declare function syncCancelable(f: (ctx: CancelToken) => R): R | void; /** Async cancelable */ export declare function cancelable(f: (ctx: CancelToken) => Promise): Promise; /** Task Like */ export interface TaskLike extends CancelToken, PromiseLike { /** Run task */ run(): PromiseLike; /** Is running */ running: boolean; /** Whether finished */ finished: boolean; } /** Cancelable async task */ export declare class Task implements TaskLike, Promise { #private; /** Creates a new Task */ constructor(f: (self: Task) => PromiseLike); /** Creates a new Task with CancelToken */ constructor(token: CancelToken, f: (self: Task) => PromiseLike); /** Communicates a request for cancellation */ cancel(): void; /** If cancelled, throw CancelGuard */ guard(): void; /** If cancelled will not continue */ aguard(): Promise; /** Register an event that will be triggered when cancelled */ reg(f: () => any): void; /** Waiting for cancellation */ reg(): Promise; /** Unregister event */ unReg(f: () => any): void; /** Has it been cancelled or whether cancellation has been requested */ get cancelled(): boolean; /** Whether finished */ get finished(): boolean; /** Is running */ get running(): boolean; /** Run task * * Even if this function is not called the task will still run */ run(): Promise; /** Attaches callbacks for the resolution and/or rejection of the Promise. */ then(onfulfilled?: ((value: T | void) => TResult1 | PromiseLike) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike) | null): Promise; /** Attaches a callback for only the rejection of the Promise. */ catch(onrejected?: ((reason: any) => TResult | PromiseLike) | null): Promise; [Symbol.toStringTag]: string; /** Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The resolved value cannot be modified from the callback. */ finally(onfinally?: (() => void) | null): Promise; /** Run Task */ static run(f: (self: Task) => PromiseLike): Task; /** Run Task with CancelToken */ static run(token: CancelToken, f: (self: Task) => PromiseLike): Task; /** Run task with promise parameters * @param executor A callback used to initialize the promise. This callback is passed two arguments: * a resolve callback used to resolve the promise with a value or the result of another promise, * and a reject callback used to reject the promise with a provided reason or error. */ static exec(executor: (self: Task, resolve: (value: T | PromiseLike) => void, reject: (reason?: any) => void) => void): Task; /** Run task with promise parameters with CancelToken * @param executor A callback used to initialize the promise. This callback is passed two arguments: * a resolve callback used to resolve the promise with a value or the result of another promise, * and a reject callback used to reject the promise with a provided reason or error. */ static exec(token: CancelToken, executor: (self: Task, resolve: (value: T | PromiseLike) => void, reject: (reason?: any) => void) => void): Task; /** Cancelable async delay */ static delay(ms?: number): Task; /** Cancelable async delay with CancelToken */ static delay(token: CancelToken, ms?: number): Task; /** Yield time slice and not continue if cancelled */ static yield(token?: CancelToken): Task; /** Yield time slice and not continue if cancelled, using this as CancelToken */ yield(): Task; /** Cancelable async delay, using this as CancelToken */ delay(ms?: number): Task; /** Run Task, using this as CancelToken */ subRun(f: (self: Task) => PromiseLike): Task; /** Run task with promise parameters, using this as CancelToken * @param executor A callback used to initialize the promise. This callback is passed two arguments: * a resolve callback used to resolve the promise with a value or the result of another promise, * and a reject callback used to reject the promise with a provided reason or error. */ exec(executor: (self: Task, resolve: (value: T | PromiseLike) => void, reject: (reason?: any) => void) => void): Task; /** Creates a new cancelled task * @returns A cancelled task */ static abort(): Task; /** * Creates a new resolved task. * @returns A resolved task. */ static resolve(): Task; /** * Creates a new resolved task for the provided value. * @param value A task. * @returns A task whose internal state matches the provided task. */ static resolve(value: T | PromiseLike): Task; /** * Creates a new rejected promise for the provided reason. * @param reason The reason the promise was rejected. * @returns A new rejected Promise. */ static reject(reason?: any): Task; /** Wait or cancel all task */ static all(token: CancelToken, ...args: T): Task<{ [K in keyof T]: T[K] extends PromiseLike ? V : T[K]; }>; /** Wait or cancel all task */ all(...args: T): Task<{ [K in keyof T]: T[K] extends PromiseLike ? V : T[K]; }>; /** Wait one and cancel other task */ static race(token: CancelToken, ...args: T[]): Task ? U : T>; /** Wait one and cancel other task */ race(...args: T[]): Task ? U : T>; static scope>(token: CancelToken, promise: T): Promise ? R : T>; static scope>(token: CancelToken, promise: T): Promise ? R : T>; static scope(token: CancelToken, promise: T): Promise ? R : T>; scope>(promise: T): Promise ? R : T>; scope>(promise: T): Promise ? R : T>; scope(promise: T): Promise ? R : T>; }