matthew-andrews / isomorphic-fetch

Isomorphic WHATWG Fetch API, for Node & Browserify
MIT License
6.95k stars 289 forks source link

Timeout #147

Open justfede opened 6 years ago

justfede commented 6 years ago

Hi guys? There's anyway to set a timeout? (Without use a setTimeout() and throw some error manually)

PS: I'm using react.

Thanks!

OpenDog commented 6 years ago

Nada?

jimmywarting commented 5 years ago

possible duplicate of #48? so can this be closed?

Also a timeout isn't the right solution for aborting a fetch request as it will continue to download if you wrap the fetch promise with a timeout race.

The right solution is to use abortcontroller

const controller = new AbortController()
const signal = controller.signal

setTimeout(() => { 
  controller.abort()
}, 1000)

fetch(url, { signal })
ianstormtaylor commented 4 years ago

FWIW, I've opened an issue https://github.com/whatwg/fetch/issues/951 with a proposal for a timeout option that solves 90% of use cases, in case anyone's interested. I think it's super important to add to make sure calls to fetch (or res.json()) don't hang indefinitely.