UNPKG

@sapphire/utilities

Version:
39 lines (36 loc) 1.67 kB
import { Awaitable } from './types.mjs'; /** The options for the {@link poll} function */ interface PollOptions { /** * An optional AbortSignal to abort the polling. */ signal?: AbortSignal | undefined; /** * The amount of attempts to try, if any. * @default Infinite */ maximumRetries?: number | null | undefined; /** * The amount of time to wait between each poll. * @default 0 */ waitBetweenRetries?: number | null | undefined; /** * Whether to log to the console on each polling interval, allowing the tracing of the amount of required attempts. * @default false */ verbose?: boolean | undefined; } /** * Executes a function {@link cb} and validates the result with function {@link cbCondition}, * and repeats this until {@link cbCondition} returns `true` or the {@link timeout} is reached. * * For a synchronous variant, see [pollSync](./pollSync.d.ts). * @param cb The function that should be executed. * @param cbCondition A function that when given the result of `cb` should return `true` if the polling should stop and should return `false` if the polling should continue. * @param options Options to provide further modifying behaviour. * @returns The result of {@link cb} as soon as {@link cbCondition} returns `true`, or an error if {@link timeout} is reached. * @throws If {@link timeout} is reached. */ declare function poll<T>(cb: (signal: AbortSignal | undefined) => Awaitable<T>, cbCondition: (value: Awaited<T>, signal: AbortSignal | undefined) => Awaitable<boolean>, options?: PollOptions): Promise<Awaitable<T>>; export { type PollOptions, poll };