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

@MattiasBuelens commented on this pull request.



> @@ -2,6 +2,8 @@
 interface ReadableStream {
   constructor(optional object underlyingSource, optional QueuingStrategy strategy = {});
 
+  static ReadableStream from(any asyncIterable);

It makes sense for `Array.from(syncIterable)` and `Array.fromAsync(asyncIterable)` to be two different methods, since they also return different results (`Array` versus `Promise<Array>`).

I don't think such distinction is necessary from `ReadableStream`. We're never going to need *both* `ReadableStream.from()` and `ReadableStream.fromAsync()`. A `ReadableStream` is *inherently* asynchronous, so we never need to return a `Promise<ReadableStream>`.

Node.js also has [`Readable.from()`](https://nodejs.org/dist/latest-v18.x/docs/api/stream.html#streamreadablefromiterable-options), which also accepts both sync and async iterables.

I think `ReadableStream.from()` is still be the better option. It makes it clear that this is *the* primary method to convert anything into a `ReadableStream`. A `from()` method usually also implies "idempotency", that is: passing an array to `Array.from()` returns a new array. On the other hand, `fromAsync()` feels more "foreign".

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

Message ID: <whatwg/streams/pull/1083/review/993349479@github.com>

Received on Thursday, 2 June 2022 10:46:34 UTC