Created
December 20, 2017 20:50
-
-
Save carpeliam/3a75e7fa57668830de5a93ab242a4c9e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 wrapPromiseInTimeout(promise) { | |
const possibleError = new Error(); | |
return new Promise((resolve, reject) => { | |
const timeoutID = setTimeout(() => reject(possibleError), 1000); | |
promise.then(resolve).catch(reject).finally(() => clearTimeout(timeoutID)); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment