Skip to content
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

Retry: Retry If Retruned Object Meets a Condition #45

Open
AhmedNourJamalElDin opened this issue Jun 1, 2020 · 7 comments · May be fixed by #55
Open

Retry: Retry If Retruned Object Meets a Condition #45

AhmedNourJamalElDin opened this issue Jun 1, 2020 · 7 comments · May be fixed by #55
Labels
enhancement New feature or request good first issue Good for newcomers pkg:retry

Comments

@AhmedNourJamalElDin
Copy link

Hi,

I'd like to retry if the returned object meets a condition.

Example:

      final response = await retry(
      // Make a GET request
      () => http.get('https://google.com'),
      // Retry on Exception
      retryIf: (e) => e is SocketException,
      retryIfReturnedObject: (o) => o == "retry-please"
  );

is this possible?
Thanks

@AhmedNourJamalElDin AhmedNourJamalElDin added pending-triage Issue is pending triage pkg:retry labels Jun 1, 2020
@AhmedNourJamalElDin AhmedNourJamalElDin changed the title Retry If Retruned Object Meets a Condition Retry: Retry If Retruned Object Meets a Condition Jun 1, 2020
@jonasfj jonasfj added the enhancement New feature or request label Jul 14, 2020
@jonasfj
Copy link
Member

jonasfj commented Jul 14, 2020

IMO, it would be ideal to the function called throw an Exception instead..

But I can see that something like package:http won't throw on 5xx responses, you if you want to retry those, this would be pretty neat.

@jonasfj jonasfj added good first issue Good for newcomers and removed pending-triage Issue is pending triage labels Jul 14, 2020
@jonasfj
Copy link
Member

jonasfj commented Jul 14, 2020

quick note: I wonder if we could call it retryIfValue instead of retryIfReturnedObject which rather long...
Or maybe retryOnReturnIf, other good names?

@jonasfj
Copy link
Member

jonasfj commented Jul 14, 2020

retryValueIf might be solid..

@Ascenio
Copy link

Ascenio commented Sep 7, 2020

Maybe we could just rename the parameters to be more descriptive, for example:

final response = await retry(
    // Make a GET request
    () => http.get('https://google.com'),
    // Retry on Exception
    retryOnException: (e) => e is SocketException,
    retryOnSuccess: (o) => o == "retry-please"
);

@Sebsen
Copy link

Sebsen commented Dec 13, 2020

That's exactly the thing I missed/ I'd like to suggest!

I like @Ascenio's idea to rename the parameters (although it is a breaking change, which requires users to adjust their code). I'd prefer an even 'simpler' renaming like the following:

final response = await retry(
    // Make a GET request
    () => http.get('https://google.com'),
    // Retry on Exception
    retryOnException: (e) => e is SocketException, // or could also be "retryOnError" - sounds even better to me
    retryIf: (o) => o == "retry-please"

);

This would have been the 'intuitive' API I would have expected on my first use.
Overall thanks for considering this and BR

@nwparker
Copy link

nwparker commented Jun 5, 2021

How about:
retryIf (for exceptions)
retryOn (for values)

We don't break anything this way

@rajada1
Copy link

rajada1 commented Mar 7, 2022

any news ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers pkg:retry
Projects
None yet
6 participants