Skip to content

Instantly share code, notes, and snippets.

@fmoliveira
Forked from davej/fetch-timeout.js
Created June 24, 2020 19:07
Show Gist options
  • Save fmoliveira/b8bc96d64c0b2189bb5f90c54d3c9b56 to your computer and use it in GitHub Desktop.
Save fmoliveira/b8bc96d64c0b2189bb5f90c54d3c9b56 to your computer and use it in GitHub Desktop.
Add a pseudo timeout/deadline to a request using the ES6 fetch api
Promise.race([
fetch('/foo'),
new Promise((_, reject) =>
setTimeout(() => reject(new Error('Timeout')), 7000)
)
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment