retryWhen method
Implementation
Stream<T> retryWhen(
bool Function(Object error) shouldRetry, {
int maxRetries = 3,
Duration delay = const Duration(seconds: 1),
}) async* {
var retries = 0;
while (true) {
try {
await for (final item in this) {
yield item;
}
break;
} catch (e) {
if (retries >= maxRetries || !shouldRetry(e)) rethrow;
retries++;
await Future.delayed(delay);
}
}
}