( received: Record<string, unknown>[], pred: (f: Record<string, unknown>) => boolean, timeoutMs = 2000, )
| 162 | } |
| 163 | |
| 164 | async function waitFor( |
| 165 | received: Record<string, unknown>[], |
| 166 | pred: (f: Record<string, unknown>) => boolean, |
| 167 | timeoutMs = 2000, |
| 168 | ): Promise<Record<string, unknown>> { |
| 169 | const start = Date.now(); |
| 170 | while (Date.now() - start < timeoutMs) { |
| 171 | const hit = received.find(pred); |
| 172 | if (hit !== undefined) return hit; |
| 173 | await new Promise((r) => setTimeout(r, 10)); |
| 174 | } |
| 175 | throw new Error( |
| 176 | `waitFor timed out; received: ${received.map((f) => f['type']).join(', ')}`, |
| 177 | ); |
| 178 | } |
| 179 | |
| 180 | function firstPendingQuestionId(broker: QuestionService): string | undefined { |
| 181 | return (broker as unknown as { |
no test coverage detected