Skip to content

Instantly share code, notes, and snippets.

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 mdlavin/e89cfcc68692c4766e4aa3198cf6ae37 to your computer and use it in GitHub Desktop.
Save mdlavin/e89cfcc68692c4766e4aa3198cf6ae37 to your computer and use it in GitHub Desktop.
A helper to make sure that a Promise will always resolve
function safePromise (promise, timeout) {
let slowOpId;
const slowLoggingPromise = pFinally(promise, function () {
if (slowOpId) {
log.warn({slowOpId, itemKey}, 'The Promise eventually resolved');
}
});
// Don't wait on longer than `timeout` ms for the Promise
const promiseWithTimeout = pTimeout(slowLoggingPromise, timeout, function () {
slowOpId = uuid();
log.warn({slowOpId, itemKey}, 'The Promise was slower than expected');
return undefined;
});
return promiseWithTimeout;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment