| 90 | } |
| 91 | |
| 92 | class BatchServerTransport implements RpcTransport { |
| 93 | constructor(batch: string[]) { |
| 94 | this.#batchToReceive = batch; |
| 95 | } |
| 96 | |
| 97 | #batchToSend: string[] = []; |
| 98 | #batchToReceive: string[]; |
| 99 | #allReceived: PromiseWithResolvers<void> = Promise.withResolvers<void>(); |
| 100 | |
| 101 | send(message: string): void { |
| 102 | this.#batchToSend.push(message); |
| 103 | } |
| 104 | |
| 105 | async receive(): Promise<string> { |
| 106 | let msg = this.#batchToReceive!.shift(); |
| 107 | if (msg !== undefined) { |
| 108 | return msg; |
| 109 | } else { |
| 110 | // No more messages. |
| 111 | this.#allReceived.resolve(); |
| 112 | return new Promise(r => {}); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | abort?(reason: any): void { |
| 117 | this.#allReceived.reject(reason); |
| 118 | } |
| 119 | |
| 120 | whenAllReceived() { |
| 121 | return this.#allReceived.promise; |
| 122 | } |
| 123 | |
| 124 | getResponseBody(): string { |
| 125 | return this.#batchToSend.join("\n"); |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Implements the server end of an HTTP batch session, using standard Fetch API types to represent |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…