Skip to content

Instantly share code, notes, and snippets.

@pettomartino
Last active Mar 12, 2019
Embed
What would you like to do?
Retry promise
const retry = (fn, options = {}) => new Promise((resolve, reject) => {
const { retryInterval = 500, retries = 1 } = options;
fn()
.then(resolve)
.catch(err => (
(retries === 0)
? reject(err)
: setTimeout(
() => retry(fn, { retryInterval, retries: retries - 1 }).then(resolve, reject),
retryInterval,
)
));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment