-
Notifications
You must be signed in to change notification settings - Fork 24.5k
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
[fetch] how to set fetch's timeout ? #2394
Comments
Found this; { as options for https://github.com/bitinn/node-fetch Maybe worth trying, as far as I know the react native fetch is based on the default fetch api, so this might work.. |
dupe #2556 |
@simondelacourt RN uses whatwh-fetch runtime so there is no timeout by default. I have a workaround (whatwg-fetch-timeout package): #2556 (comment) I am really curious about how you enthusiast RN users out there build robust apps without having timeout and abort(). |
This answer was quite helpful, worked like a charm. |
@mrbarde It does not abort the pending HTTP request. |
@adambene yh it doesn't and that's a pain in the neck, I just use it so I can update my UI for the user. |
@mrbarde Yeah, agree. |
@simondelacourt it doesn't work with react |
I would enclose my fetch requests with async functions or promises. Then set a timeout, on the parent if the promise has not returned by the time the timeout does, stop waiting for it to return and move on. |
@WardianGames it is okay for get methods but in the case of post it would be essentisl to be able to abort the pending request after a given timeout. |
I'm doing a hack with XMLHttpRequest and return it on the returned request with the "abort" method attached to the returned promise that has a closure to the xhr object. The calling code can then assign itself the request and abort it later. Not elegant but works. Chaining in promises basically breaks it unless you get the first reference to the request. I use it like this.
where this.request is held on to and aborted if more requests are made. Still experimenting with this but seems to work for not queuing up too many requests so far. The code is kind of like this but still tweaking.
|
i am still searching for the solution using fetch and timeout but..... it gets me searching all day |
dear all,
how to set fetch's timeout ?
The text was updated successfully, but these errors were encountered: