whatwg / fetch

Fetch Standard
https://fetch.spec.whatwg.org/
Other
2.11k stars 329 forks source link

Add timeout option #20

Closed wheresrhys closed 2 years ago

wheresrhys commented 9 years ago

Most ajax libraries and xhr itself offer a convenient way to set a timeout for a request. Adding timeout to the properties accepted in the options object therefore seems like a sensible addition to fetch.

https://github.com/github/fetch/pull/68

annevk commented 2 years ago

Thanks, yeah, this can be closed. We still have #179 and #180 for the more complicated scenarios.

karlhorky commented 2 years ago

AbortSignal.timeout looks great, thanks to everyone who worked on speccing and implementing this! (whatwg/dom#1032, w3ctag/design-reviews#711)

// Fetch the URL, cancelling after 8 seconds
fetch(url, { signal: AbortSignal.timeout(8000) });

Apparently available in Firefox 100 and [Chrome 103 beta](https://blog.chromium.org/2022/05/chrome-103-beta-early-navigation-hints.html#:~:text=abortsignal.timeout()%20static%20method)!!

saschanaz commented 2 years ago

And in Firefox 100 😉

karlhorky commented 2 years ago

Thanks, wasn't aware about this, updated my post above!