Great article, you just answered the reason of something I struggled to understand “TypeError: medallists is not iterable”. :-)
Thanks! I am glad it was useful for you :)
interesting mentioning how Readable streams are async iterable, but not showing the use of pipeline() in the example given where one would await once(writable, 'drain')
probably could be replaced by just yielding in that generator and having a pipeline such that:
await once(writable, 'drain')
const p = util.promisify(pipeline);
await p([readable, generator_code_here, writable]);
EDIT: unrelated but interesting related to iterators: but hopefully soon we can have https://github.com/tc39/proposal-iterator-helpers as well.
Thanks, this is a great point. I actually prefer the pipeline function most of the time when dealing with “piping” streams.
I was not aware that you could use a generator in a pipeline through. I only knew you could create “Readable” streams from generators using stream.Readable.from (https://nodejs.org/api/stream.html#stream_stream_readable_from_iterable_options). I must try this one out. It might be a great addition to the post!
for await of
I wish there was a better unification of sync/async, and particularly promises vs streams.