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 Policy with delay #115

Closed
ntimesc opened this issue Aug 8, 2022 · 6 comments
Closed

Retry Policy with delay #115

ntimesc opened this issue Aug 8, 2022 · 6 comments
Assignees
Labels
question Further information is requested

Comments

@ntimesc
Copy link

ntimesc commented Aug 8, 2022

Not sure, how to configure or implement Retry Policy with a delay. Currently, I am using RetryPolicy for refresh token but would like to extend its usage by handling the no internet connectivity retry and for that i am trying to capture the exception in this function shouldAttemptRetryOnException and returning true. However, this function immediately tries 3 attempts back to back without any delay. So would like to know what how can I add a delay in between or is there anything in http_interceptor to configure delays between requests.


import 'package:http_interceptor/http_interceptor.dart';

class RefreshAndRetryTokenPolicy extends RetryPolicy {
  @override
  int get maxRetryAttempts => 3;

   @override
   bool shouldAttemptRetryOnException(Exception reason)  {
     print('Exception in policy  $reason');

   
    //when no internet connection encountered, allow user to retry the same request

     return true;
   }

  @override
  Future<bool> shouldAttemptRetryOnResponse(ResponseData response) async {
   
    //currently handling refresh token successfully
	
    return true;
  }
}

@ntimesc ntimesc added the question Further information is requested label Aug 8, 2022
@CodingAleCR
Copy link
Owner

Hi, I think there's no way to asynchronously wait a few seconds before retrying at the moment.

This makes me think I should make shouldAttemptRetryOnException into a Future<bool> so that it supports this kind of behaviors and then you could maybe use Future.delayed in these cases (that might make the request stay "loading" until it is either resolved or rejected, which is something to look out for).

@ntimesc
Copy link
Author

ntimesc commented Aug 10, 2022

Hi, I think there's no way to asynchronously wait a few seconds before retrying at the moment.

This makes me think I should make shouldAttemptRetryOnException into a Future<bool> so that it supports this kind of behaviors and then you could maybe use Future.delayed in these cases (that might make the request stay "loading" until it is either resolved or rejected, which is something to look out for).

So when can we have this feature available :)

@CodingAleCR
Copy link
Owner

It should be available in beta.6, which is already in the automation pipeline as I'm writing this.

@CodingAleCR
Copy link
Owner

It's now out 🎉 I'm closing this but feel free to comment if it does not work as you expected 😉

@CodingAleCR
Copy link
Owner

@all-contributors add @ntimesc for ideas

@allcontributors
Copy link
Contributor

@CodingAleCR

I've put up a pull request to add @ntimesc! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants