Skip to content

Instantly share code, notes, and snippets.

@piccaso
Created January 20, 2020 08:40
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 piccaso/ea0637df7c01626192ea22cd6b853b51 to your computer and use it in GitHub Desktop.
Save piccaso/ea0637df7c01626192ea22cd6b853b51 to your computer and use it in GitHub Desktop.
async function tryHarder(howHard, delay, callback) {
let wait = (milliseconds) => new Promise(resolve => setTimeout(resolve, milliseconds));
while (true) {
try {
return await callback();
} catch (ex) {
if (--howHard < 1) throw (ex);
}
await wait(delay);
}
}
@kirby232
Copy link

nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment