Created
October 2, 2016 21:16
-
-
Save rubystream/cd7be4af6bb4da462610dd4e1a1c6538 to your computer and use it in GitHub Desktop.
Promise.race timeout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function delay(time) { | |
return new Promise(fulfill => { | |
setTimeout(fulfill, time); | |
}); | |
} | |
Promise.race([longRunningPromise, delay(time).then(function () { | |
throw new Error('Operation timed out'); | |
})]) | |
.then(value => { console.log(value); }) | |
.catch(reason => { console.log(reason); }); |
tianyk
commented
Aug 29, 2018
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment