-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
orElse callback when retries are exhausted #167
base: master
Are you sure you want to change the base?
Conversation
@@ -179,10 +184,16 @@ Future<T> retry<T>( | |||
int maxAttempts = 8, | |||
FutureOr<bool> Function(Exception)? retryIf, | |||
FutureOr<void> Function(Exception)? onRetry, | |||
FutureOr<T> Function(Exception)? orElse, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
documentation needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
if (orElse != null) { | ||
return await orElse(e); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
fn
throws an exception of type (B), - (ii)
fn
throws 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.