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

Provide an API to set fetch timeout #910

Closed
ifurnadjiev opened this issue Jun 29, 2016 · 6 comments
Closed

Provide an API to set fetch timeout #910

ifurnadjiev opened this issue Jun 29, 2016 · 6 comments
Labels

Comments

@ifurnadjiev
Copy link
Member

var start = Date.now();
fetch('http://www.eclipsesource.com:1234').then(function(){
  var end = Date.now();
  console.log("Resolved! " + (end - start) );
}).catch(function(){
  var end = Date.now();
  console.log("Rejected!" + (end - start));
});

The snippet above give different results on Android and iOS. On Android fetch rejects in 127 sec, on iOS is 75 sec. These numbers are reproducible all the time.

@mpost
Copy link
Member

mpost commented Jun 29, 2016

Is there a difference when making a direct XHR request?

@ralfstx
Copy link
Member

ralfstx commented Jun 29, 2016

Out fetch implementation doesn't set a timeout, so No.

See https://github.com/github/fetch/search?q=timeout

@cookieguru
Copy link
Contributor

Timeout isn't in the fetch spec. Additionally, it's easy to add timeout support with some straightforward wrapper code: JakeChampion/fetch#175 (comment)

@cookieguru
Copy link
Contributor

timeout parameter now available in 2.0.0 RC 1 😃

@mpost
Copy link
Member

mpost commented May 16, 2017

Hurray :)

@mpost mpost closed this as completed May 16, 2017
@ralfstx
Copy link
Member

ralfstx commented May 16, 2017

Right, after wrapping fetch in a timeout-promise one too many times, we realized that this property is really needed.

fetch(url, {
  timeout: 5000 // request timeout in ms
}).then(...);

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

No branches or pull requests

4 participants