(get: () => T, timeout = 3000, interval = 25)
| 339 | // Polls `get` until it returns a truthy value or the timeout elapses, instead |
| 340 | // of sleeping a fixed amount and hoping the (real-timer) fire already happened. |
| 341 | async function waitFor<T>(get: () => T, timeout = 3000, interval = 25): Promise<T> { |
| 342 | const deadline = Date.now() + timeout; |
| 343 | for (;;) { |
| 344 | const value = get(); |
| 345 | if (value || Date.now() > deadline) return value; |
| 346 | await new Promise(r => setTimeout(r, interval)); |
| 347 | } |
| 348 | } |