retryUntil function

bool retryUntil(
  1. bool predicate(), {
  2. int maxAttempts = 10,
})

Calls predicate up to maxAttempts times, returning true as soon as it succeeds, or false if every attempt fails.

Example:

retryUntil(() => randomBool(), maxAttempts: 5);

Implementation

bool retryUntil(bool Function() predicate, {int maxAttempts = 10}) {
  for (int i = 0; i < maxAttempts; i++) {
    if (predicate()) return true;
  }
  return false;
}