Created
September 22, 2017 21:38
-
-
Save rjz/7cf2e92bd894979070fcfe5ef51338e6 to your computer and use it in GitHub Desktop.
Expiring promise
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
const expiresIn = (timeoutMs, promise, msg = 'Promise timed out') => | |
new Promise((resolve, reject) => { | |
const timerId = setTimeout(reject, timeoutMs, msg); | |
promise.then((result) => { | |
clearTimeout(timerId); | |
resolve(result); | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment