@sapphire/utilities
Version:
Common JavaScript utilities for the Sapphire Community
26 lines (23 loc) • 1.2 kB
text/typescript
import { PollOptions } from './poll.cjs';
import './types.cjs';
/** The options for the {@link pollSync} function */
interface SyncPollOptions extends Omit<PollOptions, 'signal'> {
/**
* The amount of milliseconds before throwing an AbortError.
* @default Infinite
*/
timeout?: number | null | 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 an asynchronous variant, see [poll](./poll.d.ts).
* @param cb The function that should be executed.
* @param cbCondition A function that when given the result of `fn` 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 pollSync<T>(cb: () => T, cbCondition: (value: T) => boolean, options?: SyncPollOptions): T;
export { type SyncPollOptions, pollSync };