Repeatedly executes a function until a specified condition is met or a maximum number of attempts is reached.
Useful for retrying an operation with an interval or condition check.
The result of fn once the predicate is satisfied or the maximum attempts are reached.
Example
// Attempts to generate a valid email address, retrying up to 5 times constresult = repeatUntil(generateEmail, email=>email.includes('@'), 5);
Example
// Retries generating a random number between 1 and 5 until it's greater than 3 constnumber = repeatUntil(() =>Math.floor(Math.random() * 5) + 1, n=>n > 3); console.log(number); // Outputs a number greater than 3
Repeatedly executes a function until a specified condition is met or a maximum number of attempts is reached. Useful for retrying an operation with an interval or condition check.