Skip to content

Instantly share code, notes, and snippets.

@RyanChill94
Last active August 6, 2018 06:38
Show Gist options
  • Select an option

  • Save RyanChill94/90a03884acd62cd625ca1a3fb4b634df to your computer and use it in GitHub Desktop.

Select an option

Save RyanChill94/90a03884acd62cd625ca1a3fb4b634df to your computer and use it in GitHub Desktop.
timeout checking
const delay = (ms) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
reject(new Error('timeout'))
}, ms)
})
}
const fetchWithTimeout = (timeout, ...args) => {
return Promise.race([fetch(...args), delay(timeout)]) // decided by the first promise resolve
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment