-
Notifications
You must be signed in to change notification settings - Fork 209
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
Allow passing timeout and/or AbortSignal to auth.refreshToken() #409
Comments
@mnylen 👋
Reference: https://qnp.co.id/blog/adding-timout-fetch-api/ Would you like to send a PR with any of the options above? |
@lbalmaceda Ideally I'd like it to be customisable in a way that you could pass your own abort signal (someone might want to cancel the request based on other factors than just timeout) for each request (same signal can't be reused between requests), but it definitely is easier to just implement a global timeout of 10 seconds. I can take a stab at making a PR for this, although it might take a good while before I have the time for it. |
* Implement timeout support to networking Client * Change test timeout to 2 seconds Co-authored-by: Rita Zerrizuela <[email protected]>
This can be closed now that the timeout support was merged. |
Describe the problem you'd like to have solved
If user's phone has a bad network connection, the
auth.refreshToken()
call might end up taking a very long time, and in the worst case, will never succeed or fail.To simulate this happening in iOS, you can install Network Link Conditioner and select the 100 % Loss profile.
Describe the ideal solution
Ideally I would like to be able to pass a timeout parameter to
auth.refreshToken()
call that makes sure the operation completes after the given timeout, no matter what. Ideally the timeout implementation should pass anAbortSignal
to the underlyingfetch()
call and cancel the request when the timeout occurs.Of course, this functionality should probably be made available to all methods that make network requests, not just
auth.refreshToken()
.It would also be nice if the caller could pass their own
AbortSignal
, if they want to implement custom timeout or cancellation logic.Alternatives and current work-arounds
It is possible to implement timeout now by creating another promise that rejects after given timeout, and then using
Promise.race
:However, this solution is only partial: it won't cancel the request. To be able to cancel the
fetch
request, anAbortSignal
is needed and there is currently no way to pass that.Additional information, if any
The text was updated successfully, but these errors were encountered: