MCPcopy Create free account
hub / github.com/WinterTC55/iter-streams / flattenTransformYieldAsync

Function flattenTransformYieldAsync

src/pull.ts:152–178  ·  view source on GitHub ↗

* Flatten transform yield to Uint8Array chunks (async).

(
  value: TransformYield | AsyncIterable<TransformYield>
)

Source from the content-addressed store, hash-verified

150/**
151 * Flatten transform yield to Uint8Array chunks (async).
152 */
153async function* flattenTransformYieldAsync(
154 value: TransformYield | AsyncIterable<TransformYield>
155): AsyncGenerator<Uint8Array> {
156 if (value instanceof Uint8Array) {
157 yield value;
158 return;
159 }
160 if (typeof value === 'string') {
161 yield encoder.encode(value);
162 return;
163 }
164 // Check for async iterable first
165 if (isAsyncIterable(value)) {
166 for await (const item of value) {
167 yield* flattenTransformYieldAsync(item as TransformYield);
168 }
169 return;
170 }
171 // Must be sync Iterable<TransformYield>
172 if (isSyncIterable(value)) {
173 for (const item of value) {
174 yield* flattenTransformYieldAsync(item as TransformYield);
175 }
176 return;
177 }
178 throw new TypeError(`Invalid transform yield type: ${typeof value}`);
179}
180
181/**

Callers 3

Calls 2

isAsyncIterableFunction · 0.90
isSyncIterableFunction · 0.90

Tested by

no test coverage detected