waitUntilAsync method

Future<int> waitUntilAsync(
  1. Future<bool> test(), {
  2. int maxIterations = 1000,
  3. Duration step = const Duration(milliseconds: 10),
})

Implementation

Future<int> waitUntilAsync(Future<bool> Function() test,
    {final int maxIterations = 1000,
    final Duration step = const Duration(milliseconds: 10)}) async {
  int iterations = 0;
  for (; iterations < maxIterations; iterations++) {
    await Future.delayed(step);
    if (await test()) {
      break;
    }
  }
  if (iterations >= maxIterations) {
    throw TimeoutException(
        'Condition not reached within ${iterations * step.inMilliseconds}ms');
  }
  return iterations;
}