Being able to pause requests
vixez opened this issue · comments
Is your feature request related to a problem? Please describe.
The app I'm building can fire multiple requests at once.
When one of the requests gets a 401 for an expired token, it updates the token in a RetryPolicy
.
During this update, all other requests should be paused as a new token is being retrieved.
Describe the solution you'd like
Be able to pause requests in the queue, and resume them. For example pausing the queue when a new token is being retrieved.
After the token is updated, all requests in the queue should have their interceptRequest
method called, so the request can be updated with the new token (if an old token is in the request).
An alternative would be that everything runs in a sequence, no simultaneous requests.
- Request 1: Added to queue
- Request 1:
interceptRequest
- Request 2: Added to queue
- Request 1: 401 =>
RetryPolicy
+ pause all requests in the queue - Request 1: Asynchronously finish
shouldAttemptRetryOnResponse
(token in storage updated) - Request 1: Retry so >
interceptRequest
- Request 1: finish successfully
- Request 2:
interceptRequest
- Request 2: finish successfully
- ...
I have created a PR for how I currently solved this issue.
Really interesting FR (Feature Request). Is this request based on the need for having multiple requests but refresh token only once for all subsequent requests?
This could be interesting as well if the "pausing" was performed when the retry policy is triggered instead of always as well, in any case, how would you feel about this?
Hey,
Yes, we use the client to talk to our own backend. So when one of the requests returns a 401 all future requests should wait until the token is refreshed.
If the token fails to refresh it could be nice to cancel further requests, since they will fail anyway without a token.
Maybe requests could be 'grouped' by a GUID, or adding tags to requests. With some way to cancel requests that belong to a certain group/tag.
This would be convenient to cancel pending requests when a user is logged out due to an expired token, and cancel pending requests that user authentication. Se that group or tag would be cancelled then.
@CodingAleCR
I have created a PR with how I implemented it in my app (both the limiting and pausing of requests), albeit a bit more abstract.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Hey @CodingAleCR please take a look on this issue. The bot seems not not like it and keeps closing xD
Any developments on this feature?
There's a PR outdated that deals with pooling requests and working on pauses. But other than that there's no current development at the moment.
Feel free to drop a PR with an implementation if that's something you think could help 😉👌🏼
Thank you both for bringing this up as well!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.