Created
January 20, 2020 08:40
-
-
Save piccaso/ea0637df7c01626192ea22cd6b853b51 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice