- From: Mattias Buelens <notifications@github.com>
- Date: Tue, 29 Dec 2020 09:43:01 -0800
- To: whatwg/streams <streams@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/streams/pull/1083/review/559635812@github.com>
@MattiasBuelens commented on this pull request. > + 1. Let |startAlgorithm| be the following steps: + 1. Set |iteratorRecord| to ? [$GetIterator$](|asyncIterable|, async). + 1. Let |pullAlgorithm| be the following steps: + 1. Let |nextResult| be [$IteratorNext$](|iteratorRecord|). + 1. If |nextResult| is an abrupt completion, return [=a promise rejected with=] + |nextResult|.\[[Value]]. + 1. Let |nextPromise| be [=a promise resolved with=] |nextResult|.\[[Value]]. + 1. Return the result of [=reacting=] to |nextPromise| with the following fulfillment steps, + given the argument |iterResult|: + 1. If [$Type$](|iterResult|) is not Object, throw a {{TypeError}}. + 1. Let |done| be ? [$IteratorComplete$](|iterResult|). + 1. If |done| is true: + 1. Perform ! [$ReadableStreamDefaultControllerClose$](stream.[=ReadableStream/[[controller]]=]). + 1. Otherwise: + 1. Let |value| be ? [$IteratorValue$](|iterResult|). + 1. Perform ! [$ReadableStreamDefaultControllerEnqueue$](stream.[=ReadableStream/[[controller]]=], One possible use case would be if you had an (slow) async iterable, and you wanted to quickly add buffering around it: ```javascript const bufferedReadable = ReadableStream .from(createSlowIterable(), new CountQueuingStrategy({ highWaterMark: 10 })); ``` That said, you can also achieve this with an intermediate `TransformStream`, which is already explained in [this example](https://streams.spec.whatwg.org/#example-transform-identity): ```javascript const slowReadable = ReadableStream.from(createSlowIterable()); const bufferedReadable = slowReadable .pipeThrough(new TransformStream(undefined, new CountQueuingStrategy({ highWaterMark: 10 }))); ``` (Note that this assumes that `ReadableStream.from` creates a stream with HWM = 0, [see other thread](https://github.com/whatwg/streams/pull/1083#discussion_r549040797).) I don't know how compelling this use case is though... 🤷 -- 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_r549791321
Received on Tuesday, 29 December 2020 17:43:16 UTC