Last active
March 13, 2018 14:09
-
-
Save cmseaton42/c3672652da425e8caffb5177ce0ba1ec to your computer and use it in GitHub Desktop.
Promise 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 timeout = (promise, ms, error = new Error("Promise TIMEOUT Occurred!!!")) => { | |
return new Promise((resolve, reject) => { | |
// Set Timer | |
const timer = setTimeout(() => reject(error), ms) | |
// Handle Passed Promise | |
promise | |
.then(resolve) | |
.catch(reject) | |
.finally(() => clearTimeout(timer)); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment