Skip to content

Commit

Permalink
enhance(node-fetch): make ReadableStream[Symbol.asyncIterator] `Asy…
Browse files Browse the repository at this point in the history
…ncIterableIterator` rather than `AsyncIterator` only (#1961)
  • Loading branch information
ardatan authored Jan 10, 2025
1 parent 6dc3d3f commit 2785c80
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .changeset/afraid-lies-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@whatwg-node/node-fetch': patch
'@whatwg-node/fetch': patch
---

`ReadableStream`'s `Symbol.asyncIterator` now returns `AsyncIterableIterator` like before even if it
is ok to return `AsyncIterator` right now. It is safer to return `AsyncIterableIterator` because it is a common mistake to use `AsyncIterator` as `AsyncIterable`.
3 changes: 3 additions & 0 deletions packages/node-fetch/src/ReadableStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ export class PonyfillReadableStream<T> implements ReadableStream<T> {
[Symbol.asyncIterator]() {
const iterator = this.readable[Symbol.asyncIterator]();
return {
[Symbol.asyncIterator]() {
return this;
},
next: () => iterator.next(),
return: () => {
if (!this.readable.destroyed) {
Expand Down

0 comments on commit 2785c80

Please sign in to comment.