| 91 | } |
| 92 | |
| 93 | waitForId(id: string, timeoutMs: number): Promise<JsonRpcMessage> { |
| 94 | const existing = this.messages.find((message) => message.id === id); |
| 95 | if (existing) return Promise.resolve(existing); |
| 96 | return new Promise((resolve, reject) => { |
| 97 | const timeout = setTimeout(() => { |
| 98 | // oxlint-disable-next-line executor/no-promise-reject, executor/no-error-constructor -- boundary: Promise timeout adapter for e2e polling. |
| 99 | reject(new Error(`timed out waiting for JSON-RPC id ${id}`)); |
| 100 | }, timeoutMs); |
| 101 | const waiter = { |
| 102 | resolve: (message: JsonRpcMessage) => { |
| 103 | clearTimeout(timeout); |
| 104 | resolve(message); |
| 105 | }, |
| 106 | }; |
| 107 | this.waiters.set(id, [...(this.waiters.get(id) ?? []), waiter]); |
| 108 | }); |
| 109 | } |
| 110 | |
| 111 | abort(reason: string): void { |
| 112 | this.abortController?.abort(reason); |