waitUntil
waitUntil<
T
>(condition
,options
):Promise
<T
>
Repeatedly evaluates a synchronous or asynchronous condition function until it returns a truthy value, using exponential backoff between retries.
Supports an overall timeout and optional AbortSignal for cancellation.
Type Parameters
Section titled “Type Parameters”T
Return value
Parameters
Section titled “Parameters”condition
Section titled “condition”() => T
| Promise
<T
>
A function that returns a truthy value or a Promise resolving to truthy.
waitUntil
resolves with that truthy value.
options
Section titled “options”WaitUntilOptions
= {}
Settings for how long and how often to retry.
Returns
Section titled “Returns”Promise
<T
>
Resolves with the first truthy result from condition
.
Throws
Section titled “Throws”If the provided signal
is aborted, or the timeout
elapses.
Examples
Section titled “Examples”// Wait for a DOM element to appear (up to 5 seconds)const btn = await waitUntil( () => document.querySelector<HTMLButtonElement>('#submit'), { timeout: 5000 })btn.click()
// Poll an API until it reports readinessconst readyData = await waitUntil( async () => { const resp = await fetch('/api/status') const json = await resp.json() return json.ready ? json : null }, { initialInterval: 100, maxInterval: 2000, timeout: 15000 })console.log('Service is ready:', readyData)