Retries an asynchronous function until a given condition returns true or the maximum number of retries is reached.
true
Each attempt waits for the previous promise to resolve before checking the condition. A delay is applied between retries.
The type of the value returned by the async function.
The asynchronous function to execute.
A predicate function that checks if the result is acceptable.
Maximum number of attempts. Defaults to 5.
5
Delay in milliseconds between retries. Defaults to 100.
100
A promise that resolves to the first result satisfying the condition, or the last result if none satisfy.
let counter = 0;const result = await retryUntil( async () => { counter++; return counter; }, (val) => val >= 3, 5, 100);console.log(result); // 3 Copy
let counter = 0;const result = await retryUntil( async () => { counter++; return counter; }, (val) => val >= 3, 5, 100);console.log(result); // 3
1.1.0
Retries an asynchronous function until a given condition returns
true
or the maximum number of retries is reached.Each attempt waits for the previous promise to resolve before checking the condition. A delay is applied between retries.