| 101 | } |
| 102 | |
| 103 | waitForId(id: JsonRpcId, timeoutMs: number): Promise<JsonRpcMessage> { |
| 104 | const existing = this.messages.find((message) => message.id === id); |
| 105 | if (existing) return Promise.resolve(existing); |
| 106 | return new Promise((resolve, reject) => { |
| 107 | const timeout = setTimeout(() => { |
| 108 | // oxlint-disable-next-line executor/no-promise-reject, executor/no-error-constructor -- boundary: Promise timeout adapter for e2e polling. |
| 109 | reject(new Error(`timed out waiting for JSON-RPC id ${id}`)); |
| 110 | }, timeoutMs); |
| 111 | const waiter = { |
| 112 | resolve: (message: JsonRpcMessage) => { |
| 113 | clearTimeout(timeout); |
| 114 | resolve(message); |
| 115 | }, |
| 116 | }; |
| 117 | this.waiters.set(id, [...(this.waiters.get(id) ?? []), waiter]); |
| 118 | }); |
| 119 | } |
| 120 | |
| 121 | waitForFirstResponse(timeoutMs: number): Promise<JsonRpcMessage> { |
| 122 | const existing = this.messages.find( |