See the entire conversation

This seems to have gone mostly unnoticed. All readable streams in Node.js v10 are async iterators. This is really, really, big deal. for await (let c of fs.createReadStream(filename) { console.log(c) } πŸ”₯πŸ”₯πŸ”₯πŸ”₯πŸ”₯πŸ”₯πŸ”₯πŸ”₯πŸ”₯πŸ”₯πŸ”₯
18 replies and sub-replies as of May 09 2018

I even made a thing that lets you ‘pipe’ them to other streams!…
I made a @nodejs thing today, thanks to async iterators in v10. Introducing async-stream-generator: pipe your async generators through Node.js streams! streamify(generator(stream)).pipe(dest);…
Currently only works if it’s the first in the chain. I have a protype that turns your generator into a duplex/transform stream, but it needs a bit of polish still.
It made my day when I read about it for the first time
Hah, yes, I was exposing this in our coding channel the other day, it's super cool! Async iterators are so nice.
I’m looking for more examples of where these can be used?
Async iterators? They're pretty useful anywhere streams have been used. The fact that Node 10 streams are magically iterators means that you can just implement things in terms of streams and get them for free w/ backwards compat.
But yeah, object streams in particular, so I'm thinking result sets from database libraries are a big obvious use case. Output from parsers too.
In using it a ton, I'll tell you if I find any bugs :)
Experimentally, but yeah, that happened
Are there plans to have have an async version of stream.write for writeable streams? This way instead of needing to wait for drain you can just await stream.writeAsync...
Hmm I could use this with a data analytics assignment im working on. Wonder how it’ll handle reading a 200k line JSON file of data πŸ€” I guess as a stream it doesn’t matter the size as long as I step through properly and close the stream when I’m done.
I'm reading millions of lines of CSV with it ;)
I've been trying this on HTTP requests and responses to gather their bodies, but it doesn't seem to work for them (I get back an empty string/buffer). Do some streams need special handling to make it work?
Nice! This is how I always build my streams systems. Too bad it had the overhead of supporting the legacy APis. Maybe I'll make a minimal version for people who only use the iterator interface.