Closed timcash closed 4 years ago
Could be a nice thing to have. Right now createReadStream use from2
to build the readable stream but that module uses an old version of readable stream without the support for iterators.
We could update the dependencies and/or also we can add a new method to provide an iterator feed.iterator()
directly without having to use streams.
I usually pipe streams from libraries like hypercore through a passthrough stream since they mostly depend on readable-stream where this async stuff is still a WIP. 😅
Me too (I am used to it) but async iterators streams is already stable in node v12, you can do:
const { Readable } = require('stream')
async function * generate () {
yield 'a'
yield 'b'
yield 'c'
}
const readable = Readable.from(generate())
;(async () => {
for await (const chunk of readable) {
console.log(chunk)
}
})()
Yeah, honestly working with async iterators has been a lot nicer than regular streams in my experience. Especially for object streams. Been using it with hyperswarm in p2plex
and would want to do so here, too.
BTW, this is how you can get it to work with your example:
const { PassThrough } = require('stream')
async function logChunks(stream) {
for await (const chunk of stream.pipe(new PassThrough())) {
console.log(chunk);
}
}
oh that's a really cool solution, I didn't understand you before.
You’d wanna pump for error handling there. We are gonna switch all the streams over to streamx
now async iterable thanks to @martinheidegger
very nice design pattern. thank you for contributing. have a cookie🍪 or 🍪 🍪
Should feed.createReadStream be async iterable? This would allow code like