Find a JSON-RPC response with the given id (result OR error) on stdout.
(stdout: string[], id: number)
| 104 | |
| 105 | /** Find a JSON-RPC response with the given id (result OR error) on stdout. */ |
| 106 | function findResponse(stdout: string[], id: number): any | null { |
| 107 | for (const line of stdout) { |
| 108 | if (!line.trim()) continue; |
| 109 | try { |
| 110 | const parsed = JSON.parse(line); |
| 111 | if (parsed && parsed.id === id && (parsed.result !== undefined || parsed.error !== undefined)) { |
| 112 | return parsed; |
| 113 | } |
| 114 | } catch { /* not JSON */ } |
| 115 | } |
| 116 | return null; |
| 117 | } |
| 118 | |
| 119 | function waitFor<T>( |
| 120 | predicate: () => T | undefined | null | false, |