Skip to content

Conversation

ScottMacDougall
Copy link

Resolves #45

/// () => http.get('https://google.com').timeout(Duration(seconds: 5)),
/// // Retry on SocketException or TimeoutException
/// retryIf: (e) => e is SocketException || e is TimeoutException,
/// retryIfValue: (v) => v == 500,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example won't work

attempt++; // first invocation is the first attempt
try {
return await fn();
var value = await fn();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var value = await fn();
final value = await fn();

FutureOr<bool> Function(Exception) retryIf,
FutureOr<void> Function(Exception) onRetry,
FutureOr<bool> Function(dynamic) retryIfValue,
FutureOr<void> Function(dynamic) onRetryIfValue,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
FutureOr<void> Function(dynamic) onRetryIfValue,
FutureOr<void> Function(T) onRetryValue,

Why the if here? onRetry doesn't have that...

Also why are these dynamic, isn't T a better type? Will that work with void?

/// thrown, or if [retryIfValue] returns `true` for the value returned from [fn].
///
/// At every retry the [onRetry] function will be called (if given). The
/// At every retry the [onRetry] and [onRetryIfValue] functions will be called (if given). The
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be an OR, either onRetry is called or onRetryValue is called?

And don't we need to explain which is called when...

@rajada1
Copy link

rajada1 commented Mar 7, 2022

Any news ?

@Bungeefan
Copy link

Wouldn't retryIfResult and onRetryResult be better names?
"Value" seems a bit generic.

Additionally, are there any plans on merging this PR?

try {
return await fn();
var value = await fn();
if (retryIfValue == null || !(await retryIfValue(value))) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (retryIfValue == null || !(await retryIfValue(value))) {
if (attempt >= maxAttempts || retryIfValue == null || !(await retryIfValue(value))) {

Shouldn't there also be a maxAttempts check?
Otherwise, the users would have to count by themselves to not exceed the attempts if the value/result repeatedly triggers a retry. (e.g. HTTP 503 for longer than 30 seconds)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Retry: Retry If Retruned Object Meets a Condition

4 participants