Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | 4x 4x 4x 4x 4x 4x 4x 4x | export interface WaitUntilParams {
checkCondition: () => boolean
timeoutMs?: number
intervalMs?: number
}
export function waitUntil({ checkCondition, intervalMs = 250, timeoutMs = 2000 }: WaitUntilParams) {
return new Promise<void>((resolve, reject) => {
const timeoutId = setTimeout(() => {
clearInterval(interval)
reject(new Error('Timeout'))
}, timeoutMs)
const interval = setInterval(() => {
if (checkCondition()) {
clearTimeout(timeoutId)
clearInterval(interval)
resolve()
}
}, intervalMs)
})
}
|