obsidian-dev-utils
Version:
This is the collection of useful functions that you can use for your Obsidian plugin development
54 lines (53 loc) • 2.14 kB
text/typescript
/**
* @packageDocumentation
*
* AbortController utilities.
*/
/**
* A constant representing an infinite timeout.
*/
export declare const INFINITE_TIMEOUT: number;
/**
* An abort signal that aborts when any of the given abort signals abort.
*
* @param maybeAbortSignals - The abort signals to abort when any of them abort.
* @returns The abort signal that aborts when any of the given abort signals abort.
*/
export declare function abortSignalAny(...maybeAbortSignals: (AbortSignal | undefined)[]): AbortSignal;
/**
* An abort signal that never aborts.
*
* @returns The abort signal that never aborts.
*/
export declare function abortSignalNever(): AbortSignal;
/**
* An abort signal that aborts after a timeout.
*
* @param timeoutInMilliseconds - The timeout in milliseconds.
* @returns The abort signal that aborts after a timeout.
*/
export declare function abortSignalTimeout(timeoutInMilliseconds: number): AbortSignal;
/**
* Adds an abort listener to an abort signal and calls the callback if the abort signal is already aborted.
*
* @param abortSignal - The abort signal to add the listener to.
* @param callback - The callback to call when the abort signal aborts.
* @returns A function to remove the abort listener.
*/
export declare function onAbort(abortSignal: AbortSignal, callback: (abortSignal: AbortSignal) => void): () => void;
/**
* Waits for an abort signal to abort and resolves with its reason.
*
* @typeParam T - Expected type of `abortSignal.reason`.
* @param abortSignal - The abort signal to wait for.
* @returns A {@link Promise} that resolves with the reason of the abort signal.
*/
export declare function waitForAbort<T = unknown>(abortSignal: AbortSignal): Promise<T>;
/**
* Waits for an abort signal to abort and rejects with its reason.
*
* @param abortSignal - The abort signal to wait for.
* @param shouldRejectOnAbort - Whether to reject the promise if the abort signal is aborted.
* @returns A {@link Promise} that rejects with the reason of the abort signal.
*/
export declare function waitForAbort(abortSignal: AbortSignal, shouldRejectOnAbort: true): Promise<never>;