Skip to content

Instantly share code, notes, and snippets.

@nuxodin
Created February 14, 2023 23:17
Show Gist options
  • Save nuxodin/ae6b13c0f8c0d1c381b41c2b8605ba24 to your computer and use it in GitHub Desktop.
Save nuxodin/ae6b13c0f8c0d1c381b41c2b8605ba24 to your computer and use it in GitHub Desktop.
tryAgain function
function tryAgain(fn, times = 2){
try {
return fn(times);
} catch (e) {
if (times > 1) return tryAgain(fn, times-1);
throw e;
}
}
tryAgain( n => {
console.log(n+' trys left')
afsefesf();
}, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment