Skip to content

Commit

Permalink
fix(client): Conversion to async iterable from Response.body (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan authored Jan 10, 2025
1 parent a03486c commit f2adc92
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ async function connect<SingleConnection extends boolean>(
const parse = createParser<SingleConnection>();

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
for await (const chunk of toAsyncIterator(res.body!)) {
for await (const chunk of toAsyncIterable(res.body!)) {
if (typeof chunk === 'string')
throw (error = new Error(`Unexpected string chunk "${chunk}"`)); // set error as fatal indicator

Expand Down Expand Up @@ -1031,13 +1031,13 @@ async function connect<SingleConnection extends boolean>(
}

/** Isomorphic ReadableStream to AsyncIterator converter. */
function toAsyncIterator(
function toAsyncIterable(
val: ReadableStream | NodeJS.ReadableStream,
): AsyncIterable<string | Buffer | Uint8Array> {
// node stream is already async iterable
if (typeof Object(val)[Symbol.asyncIterator] === 'function') {
val = val as NodeJS.ReadableStream;
return val[Symbol.asyncIterator]();
return val;
}

// convert web stream to async iterable
Expand Down

0 comments on commit f2adc92

Please sign in to comment.