(check: () => boolean, what: string, timeout = 10_000)
| 19 | const delay = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms)); |
| 20 | |
| 21 | async function until(check: () => boolean, what: string, timeout = 10_000): Promise<void> { |
| 22 | const deadline = Date.now() + timeout; |
| 23 | while (!check()) { |
| 24 | if (Date.now() > deadline) throw new Error(`Timed out waiting for ${what}`); |
| 25 | await delay(25); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | const line = (msg: object): string => JSON.stringify({ jsonrpc: '2.0', ...msg }) + '\n'; |
| 30 | const INITIALIZE = line({ id: 1, method: 'initialize', params: {} }); |
no test coverage detected