Created
November 14, 2019 15:20
-
-
Save MD4/35091f37c4025a30a09e9fdf2ea8f51d to your computer and use it in GitHub Desktop.
Typescript promise retry
This file contains 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
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