Skip to content

Instantly share code, notes, and snippets.

@igolka97
Created August 4, 2024 16:36
Show Gist options
  • Save igolka97/5ad3bdb8aad79a80ecf8ec25bf565c81 to your computer and use it in GitHub Desktop.
Save igolka97/5ad3bdb8aad79a80ecf8ec25bf565c81 to your computer and use it in GitHub Desktop.
Retry Promise with interval untill resolve
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