waitFor function
等待某个操作符合要求
使用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);
}
}
}