Skip to main content

Function: poll()

poll<T>(cb: (signal: undefined | AbortSignal) => Awaitable<T>, cbCondition: (value: Awaited<T>, signal: undefined | AbortSignal) => Awaitable<boolean>, options: PollOptions): Promise<Awaitable<T>>

Executes a function cb and validates the result with function cbCondition, and repeats this until cbCondition returns true or the timeout is reached.

For a synchronous variant, see pollSync.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDescription
cb(signal: undefined | AbortSignal) => Awaitable<T>The function that should be executed.
cbCondition(value: Awaited<T>, signal: undefined | AbortSignal) => Awaitable<boolean>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.
optionsPollOptionsOptions to provide further modifying behaviour.

Returns

Promise<Awaitable<T>>

The result of cb as soon as cbCondition returns true, or an error if timeout is reached.

Throws

If timeout is reached.

Defined in

poll.ts:41