waitFor function

Future<void> waitFor(
  1. FutureOr<bool> fn(), {
  2. Duration delayFactor = const Duration(milliseconds: 200),
  3. int maxAttempts = 8,
})

等待某个操作符合要求

使用retry的变体来简化实现

Implementation

Future<void> waitFor(
  FutureOr<bool> Function() fn, {
  Duration delayFactor = const Duration(milliseconds: 200),
  int maxAttempts = 8,
}) async {
  for (int i = 0; i < maxAttempts; i++) {
    L.d('第 $i 次获取登录状态');
    if (await fn()) {
      break;
    } else {
      await Future.delayed(delayFactor);
    }
  }
}