orElse callback when retries are exhausted#167
Conversation
| int maxAttempts = 8, | ||
| FutureOr<bool> Function(Exception)? retryIf, | ||
| FutureOr<void> Function(Exception)? onRetry, | ||
| FutureOr<T> Function(Exception)? orElse, |
| if (orElse != null) { | ||
| return await orElse(e); | ||
| } |
There was a problem hiding this comment.
There are two kinds of exceptions here:
- (A) Exceptions that trigger a retry -- those where
retryIf(e)returns true. - (B) Exceptions that don't trigger a retry.
There are two reasons a call to retry(fn, ...) may throw:
- (i)
fnthrows an exception of type (B), - (ii)
fnthrows an exception of type (A) enough times that the number of retries have been exhausted.
Do we think it's right to call orElse in both cases (i) and (ii)?
There was a problem hiding this comment.
Oh, this is an old one that is still open :)
I think we should only have an alternative callback for (ii), and with that in mind, orElse is not the best name for it. How about afterExhausted or onAttemptsExhausted?
There was a problem hiding this comment.
I think orElse is an okay name, but we might have to document the behavior -- if we want this at all.
|
@slovnicki, feel free to make a new PR, or comment on this one. I don't think we've resolve the semantics. side note: I don't think we want breaking changes, hence throwing a |
|
I think to add stackTrace parameter for the orElse method would better |
No description provided.