Skip to content

Instantly share code, notes, and snippets.

@cmseaton42
Last active March 13, 2018 14:09
Show Gist options
  • Save cmseaton42/c3672652da425e8caffb5177ce0ba1ec to your computer and use it in GitHub Desktop.
Save cmseaton42/c3672652da425e8caffb5177ce0ba1ec to your computer and use it in GitHub Desktop.
Promise Timeout
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