Skip to content

Instantly share code, notes, and snippets.

@AaronHarris
Created August 23, 2017 01:14
Show Gist options
  • Select an option

  • Save AaronHarris/e7c86f759effbe7086ec2200f2cdfe67 to your computer and use it in GitHub Desktop.

Select an option

Save AaronHarris/e7c86f759effbe7086ec2200f2cdfe67 to your computer and use it in GitHub Desktop.
Make a promise retryable a certain number of times without balooning memory
function retry(gen /*: Function<Promise> */, try = 2) {
if (try < 1) return gen(); // will not retry
return gen().catch(retry.bind(retry, gen, i - 1))
}
// or
function retry(gen/*: Function<Promise> */, try = 2) {
function again(i) {
if (i < 1) return gen();
return gen.catch(again.bind(this, i-1));
}
return gen().catch(again.bind(this, try - 1));
}
function retry(promiseFun) {
function doPromise(promiseFun) {
return
}
return promiseFun().catch(error => {
retry
})
maxRetries = 5;
for(let i = 0; i < maxRetries; i++) {
yield promiseFun()
}
}
retry(Dao.deleteStuff).then(() => console.log('Successfully Updated Event')).catch('Max retries reached. Failed to clean PSIM_SITES');
Dao.deleteStuff().catch(retry);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment