Spin until `cond()` returns true or 2s elapses.
(cond: () => boolean)
| 423 | |
| 424 | /** Spin until `cond()` returns true or 2s elapses. */ |
| 425 | async function waitFor(cond: () => boolean): Promise<void> { |
| 426 | const deadline = Date.now() + 2000; |
| 427 | while (Date.now() < deadline) { |
| 428 | if (cond()) return; |
| 429 | await new Promise((r) => setTimeout(r, 10)); |
| 430 | } |
| 431 | throw new Error('waitFor: condition not satisfied within 2000ms'); |
| 432 | } |
no test coverage detected