Created
August 4, 2024 16:36
-
-
Save igolka97/5ad3bdb8aad79a80ecf8ec25bf565c81 to your computer and use it in GitHub Desktop.
Retry Promise with interval untill resolve
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 tryUntilSuccess (fn: () => Promise<any>, timeoutMs: number = 1000) { | |
return new Promise((resolve) => { | |
setTimeout(() => { | |
fn().catch(() => tryUntilSuccess(fn, timeoutMs)).then(resolve) | |
}, timeoutMs) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment