Skip to content

Instantly share code, notes, and snippets.

@rjz
Created September 22, 2017 21:38
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 rjz/7cf2e92bd894979070fcfe5ef51338e6 to your computer and use it in GitHub Desktop.
Save rjz/7cf2e92bd894979070fcfe5ef51338e6 to your computer and use it in GitHub Desktop.
Expiring promise
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