obsidian-dev-utils
Version:
This is the collection of useful functions that you can use for your Obsidian plugin development
83 lines (82 loc) • 2.49 kB
text/typescript
/**
* @packageDocumentation
*
* Provides a utility to execute an asynchronous function with a notice.
*/
import type { Promisable } from 'type-fest';
import type { RetryOptions } from '../Async.cjs';
/**
* Options for {@link retryWithTimeoutNotice}.
*/
export interface RetryWithTimeoutNoticeOptions {
/**
* The operation function to execute.
*
* @param abortSignal - The abort signal to listen to.
* @returns The result of the function.
*/
operationFn(this: void, abortSignal: AbortSignal): Promisable<boolean>;
/**
* The name of the operation.
*/
operationName?: string;
/**
* The retry options.
*/
retryOptions?: RetryOptions;
/**
* Whether to show a timeout notice. Default is `true`.
*/
shouldShowTimeoutNotice?: boolean;
/**
* The stack trace of the source function.
*/
stackTrace?: string;
}
/**
* Options for {@link runWithTimeout}.
*/
export interface RunWithTimeoutNoticeOptions<Result> {
/**
* The context of the function.
*/
context?: unknown;
/**
* The operation function to execute.
*
* @param abortSignal - The abort signal to listen to.
* @returns The result of the function.
*/
operationFn(abortSignal: AbortSignal): Promisable<Result>;
/**
* The name of the operation.
*/
operationName?: string;
/**
* Whether to show a timeout notice. Default is `true`.
*/
shouldShowTimeoutNotice?: boolean;
/**
* The stack trace of the source function.
*/
stackTrace?: string;
/**
* The maximum time to wait in milliseconds.
*/
timeoutInMilliseconds: number;
}
/**
* Retries the provided function until it returns true or the timeout is reached and displays a notice if the function times out.
*
* @param options - The options for the function.
* @returns A {@link Promise} that resolves when the function returns true or rejects when the timeout is reached.
*/
export declare function retryWithTimeoutNotice(options: RetryWithTimeoutNoticeOptions): Promise<void>;
/**
* Executes a function with a timeout and displays a notice if the function times out.
*
* @typeParam R - The type of the result from the asynchronous function.
* @param options - The options for the function.
* @returns The result of the function.
*/
export declare function runWithTimeoutNotice<Result>(options: RunWithTimeoutNoticeOptions<Result>): Promise<Result>;