Last active
February 1, 2018 15:52
-
-
Save renanpvaz/bb27496c8b6f8b734645bd7edb1f003c to your computer and use it in GitHub Desktop.
Promises with 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
const withTimeout = (time, f) => (...args) => ( | |
Promise.race([ | |
new Promise((_, reject) => setTimeout(reject, time, 'TIMEOUT')), | |
f(...args) | |
]) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment