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

@MattiasBuelens commented on this pull request.



> @@ -475,6 +481,8 @@ The Web IDL definition for the {{ReadableStream}} class is given as follows:
 interface ReadableStream {
   constructor(optional object underlyingSource, optional QueuingStrategy strategy = {});
 
+  static ReadableStream from(any asyncIterable);

I don't feel like there's much precedent for an API that accepts two *different* types of objects (`Iterable or FromInit`). What should happen if you pass an object that is *both* `Iterable` and `FromInit`?
```javascript
const readable = ReadableStream.from({ source: iter1, [Symbol.iterator]: () => iter2 });
// will this iterate over iter1 or iter2?
```

What's the `autoAllocateChunkSize` for? We don't really have a way to expose the BYOB request to the async iterable. Or do you expect it to be passed as an argument to `next()`?
```javascript
const readable = ReadableStream.from({
  type: bytes,
  autoAllocateChunkSize: 1024,
  iter: {
    next(view) {
      // view is controller.byobRequest.view
      // Fill it with some data
      view[0] = 0xaa;
      view[1] = 0xbb;
      view[2] = 0xcc;
      // Return the filled sub-view.
      // (This doesn't currently work, since enqueue() transfers the given view's buffer
      // and the first pull-into descriptor's buffer separately.)
      return { done: false, value: view.subarray(0, 3) };
    },
    [Symbol.iterator]() {
      return this;
    }
  }
});
```

-- 
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_r726608827

Received on Monday, 11 October 2021 22:27:12 UTC