Skip to content

Instantly share code, notes, and snippets.

@carpeliam
Created December 20, 2017 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carpeliam/3a75e7fa57668830de5a93ab242a4c9e to your computer and use it in GitHub Desktop.
Save carpeliam/3a75e7fa57668830de5a93ab242a4c9e to your computer and use it in GitHub Desktop.
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