async-stream
async-stream copied to clipboard
async
@Raynos can you please explain what kind of async streaming is missing?
function(){
return function*(){
return yield fs.readFile(nextLog)
}
}
@juliangruber you are using yield both for yielding a value from the stream and for doing something asynchronous
For example you need to open a file descriptor asynchronously. That requires a callback or a yield. You can't use a yield because you don't want to yield a file descriptor object, you just want to open it.
You can't use a callback because you can't yield in a callback
Interesting, I re-read the spec. Your implementing a stream as a stateful generator function that will return a value from the stream each time it's called.
That is actually possible to do, hmm.
There are probably cases where this is awkward too but so far if all is pulling that's cool and if a source is pusing you can use https://github.com/segmentio/co-queue to buffer:
function wrap(emitter, event){
var queue = new Queue;
emitter.on(event, queue.push);
return function*(end){
if (!end) return yield queue.next;
};
}
var read = wrap(emitter, 'data');
while (true) console.log(yield read());