Files

20 lines
396 B
TypeScript

import { sleep } from './utils'
const RETRY_INTERVAL = 500
const MAX_RETRIES = 5
export async function waitFor(fn: () => unknown): Promise<void> {
for (let retryCount = 1; retryCount <= MAX_RETRIES; retryCount++) {
try {
await fn()
return
} catch (error) {
if (retryCount === MAX_RETRIES) {
throw error
}
await sleep(RETRY_INTERVAL)
}
}
}