mirror of
https://github.com/hanzoai/msw.git
synced 2026-09-24 17:00:34 +00:00
20 lines
396 B
TypeScript
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)
|
|
}
|
|
}
|
|
}
|