Waits for a condition function to return true or a promise that resolves to true.
true
Polls the condition at a specified interval until it returns true or the timeout is reached, in which case an error is thrown.
A function returning a boolean or a promise that resolves to boolean.
Optional configuration for polling interval and timeout.
A promise that resolves when the condition becomes true.
let ready = false;setTimeout(() => { ready = true }, 500);await waitFor(() => ready, { interval: 100, timeoutMs: 1000 });console.log("Condition met"); Copy
let ready = false;setTimeout(() => { ready = true }, 500);await waitFor(() => ready, { interval: 100, timeoutMs: 1000 });console.log("Condition met");
Will throw an error if the condition is not met within the timeout.
1.2.0
Waits for a condition function to return
true
or a promise that resolves totrue
.Polls the condition at a specified interval until it returns
true
or the timeout is reached, in which case an error is thrown.