Skip to content

Instantly share code, notes, and snippets.

@pietmichal
Created May 19, 2017 08:46
Show Gist options
  • Select an option

  • Save pietmichal/fc76362cbca520aa9c5b0a4dd2c8dce0 to your computer and use it in GitHub Desktop.

Select an option

Save pietmichal/fc76362cbca520aa9c5b0a4dd2c8dce0 to your computer and use it in GitHub Desktop.
function retryablePromise(retries) {
return new Promise((resolve, reject) => {
reject();
})
.catch(() => {
if (retries > 0) {
return retryablePromise(retries - 1);
} else {
return Promise.reject();
}
});
}
retryablePromise(5)
.then(() => {
console.log('resolved!');
})
.catch(() => {
console.log('all attempts failed');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment