Skip to content

Instantly share code, notes, and snippets.

@rbren
Created September 21, 2017 17:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbren/8b5c6224ddf87f12eec8ff2d829a978f to your computer and use it in GitHub Desktop.
Save rbren/8b5c6224ddf87f12eec8ff2d829a978f to your computer and use it in GitHub Desktop.
function timeout(ms) {
return new Promise((resolve, reject) => {
setTimeout(reject, ms);
})
}
Promise.race([readFilePromise('index.html'), timeout(1000)])
.then(data => console.log(data))
.catch(e => console.log("Timed out after 1 second"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment