(fn: () => T)
| 54 | }); |
| 55 | |
| 56 | async function until<T>(fn: () => T): Promise<T> { |
| 57 | const timeout = 1000; |
| 58 | const start = performance.now(); |
| 59 | while (true) { |
| 60 | const result = fn(); |
| 61 | if (result) { |
| 62 | return result; |
| 63 | } |
| 64 | if (performance.now() - start > timeout) { |
| 65 | throw new Error(`condition not satisfied within ${timeout}ms.`); |
| 66 | } |
| 67 | await new Promise((r) => setTimeout(r, 1)); |
| 68 | } |
| 69 | } |
no test coverage detected