MCPcopy Create free account
hub / github.com/CommandCodeAI/BaseAI / tee

Method tee

packages/core/src/common/stream.ts:152–174  ·  view source on GitHub ↗

* Splits the stream into two streams which can be * independently read from at different speeds.

()

Source from the content-addressed store, hash-verified

150 * independently read from at different speeds.
151 */
152 tee(): [Stream<Item>, Stream<Item>] {
153 const left: Array<Promise<IteratorResult<Item>>> = [];
154 const right: Array<Promise<IteratorResult<Item>>> = [];
155 const iterator = this.iterator();
156
157 const teeIterator = (queue: Array<Promise<IteratorResult<Item>>>): AsyncIterator<Item> => {
158 return {
159 next: () => {
160 if (queue.length === 0) {
161 const result = iterator.next();
162 left.push(result);
163 right.push(result);
164 }
165 return queue.shift()!;
166 },
167 };
168 };
169
170 return [
171 new Stream(() => teeIterator(left), this.controller),
172 new Stream(() => teeIterator(right), this.controller),
173 ];
174 }
175
176 /**
177 * Converts this stream to a newline-separated ReadableStream of

Callers 1

handleStreamResponseMethod · 0.45

Calls 1

iteratorMethod · 0.95

Tested by

no test coverage detected