I want to build a custom stream, counting pages recursively:
var pageStream = function(page, limit) {
return Bacon.fromBinder(function(sink) {p
if (page >= limit) {
sink(new Bacon.End());
} else {
sink(Bacon.fromArray([page]));
sink(new Bacon.Next(function() {
return pageStream(page + 1, limit);
}));
}
}).flatMapConcat(function(v) { return v; });
};
stream = pageStream(1, 5);
// If I use this code nothing is logged, why?
// stream.onEnd(function(v) {
// console.log('done');
// });
stream.log();
I want pageStream
to count up to limit
and end the stream. It can count up to the limit, but it doesn't send the final end
event.
Also if I listen to stream.onEnd
, the stream doesn't work at all.