Last active
October 27, 2016 08:37
-
-
Save itsdouges/21211a580d4b2ad93de305c5d1c144d9 to your computer and use it in GitHub Desktop.
Promise Retries
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 _ = require('lodash'); | |
module.exports = ({ retryPredicate = _.noop, retryCount = 5 } = {}) => (promiseFunc) => { | |
let retries = retryCount; | |
return function retry (...args) { | |
return promiseFunc(...args).catch((e) => { | |
if (retryPredicate(e) && retries > 1) { | |
retries -= 1; | |
return retry(...args); | |
} | |
return Promise.reject(e); | |
}); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment