1. 15
  1.  

  2. 5

    Great article, you just answered the reason of something I struggled to understand “TypeError: medallists is not iterable”. :-)

    1. 2

      Thanks! I am glad it was useful for you :)

    2. 3

      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:

      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.

      1. 3

        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!

      2. 1

        I’ve been writing JavaScript as long as basically anybody, and I can tell you I still can’t tell you the syntax *or semantics) of for await of off the top of my head without something like this.

        I wish there was a better unification of sync/async, and particularly promises vs streams.