Re: [whatwg/streams] ReadableStream.from(asyncIterable) (#1083)

@MattiasBuelens commented on this pull request.



> @@ -1456,6 +1456,6 @@ function ReadableStreamFromIterable(asyncIterable) {
     return promiseResolvedWith(returnResult);
   }
 
-  stream = CreateReadableStream(startAlgorithm, pullAlgorithm, cancelAlgorithm);
+  stream = CreateReadableStream(startAlgorithm, pullAlgorithm, cancelAlgorithm, 0);

Another reason for setting HWM to 0: you can treat `ReadableStream.from()` as the "inverse" of `ReadableStream.prototype.values()`.
```javascript
const it1 = ['a', 'b', 'c'];
// This async iterator should behave the same as the original
const it2 = ReadableStream.from(it1).values();
for await (const chunk of it2) { /* ... */ }
```
```javascript
const rs1 = new ReadableStream({
  start(c) {
    c.enqueue('a');
    c.enqueue('b');
    c.enqueue('c');
    c.close();
  }
});
// This stream should behave the same as the original
const rs2 = ReadableStream.from(rs1.values());
const reader = rs2.getReader();
for (let result = await reader.read(); !result.done; result = await reader.read()) { /* ... */ }
```

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/pull/1083#discussion_r598005739

Received on Friday, 19 March 2021 22:30:32 UTC