Skip to content

Instantly share code, notes, and snippets.

@MD4
Created November 14, 2019 15:20
Show Gist options
  • Save MD4/35091f37c4025a30a09e9fdf2ea8f51d to your computer and use it in GitHub Desktop.
Save MD4/35091f37c4025a30a09e9fdf2ea8f51d to your computer and use it in GitHub Desktop.
Typescript promise retry
function retry<T>(promise: () => Promise<T>, maxTries = 3): Promise<T> {
return promise().catch(() =>
maxTries > 1 ? retry(promise, maxTries - 1) : promise()
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment