MCPcopy
hub / github.com/cloudflare/capnweb / BatchServerTransport

Class BatchServerTransport

src/batch.ts:92–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90}
91
92class 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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…