Skip to content

Instantly share code, notes, and snippets.

@gleydson
Created January 20, 2024 22:05
Show Gist options
  • Save gleydson/ac0d0150c598321491af725742531479 to your computer and use it in GitHub Desktop.
Save gleydson/ac0d0150c598321491af725742531479 to your computer and use it in GitHub Desktop.
async function retry<T>(fn: () => Promise<T>, retries: number = 5) {
try {
return await retry()
} catch (err) {
if (retries > 0) {
console.log("Retrying...")
return await retry(fn, retries - 1)
}
throw err
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment