Skip to content

Commit

Permalink
perf(client): Avoid recreating result variables when reading the resp…
Browse files Browse the repository at this point in the history
…onse stream
  • Loading branch information
enisdenjo committed May 4, 2022
1 parent 17dcee3 commit 16f6a6c
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -784,12 +784,11 @@ function toAsyncIterator(

// convert web stream to async iterable
return (async function* () {
val = val as ReadableStream;
const reader = val.getReader();
for (;;) {
const { value, done } = await reader.read();
if (done) return value;
yield value;
}
const reader = (val as ReadableStream).getReader();
let result;
do {
result = await reader.read();
if (result.value !== undefined) yield result.value;
} while (!result.done);
})();
}

0 comments on commit 16f6a6c

Please sign in to comment.