I'm trying to create a rate limiting when accessing an external API, using Bacon.JS
The rate limiting works fine, using bufferWithCount and bufferingThrottle but i would like to get the results when everything is flatmapped, not each batch at a time.
I've tries onEnd but it does not seem to be triggered.
Here's a fiddle: http://jsfiddle.net/9324jyLr/1/
var stream = new Bacon.Bus();
stream
.bufferWithCount(2)
.bufferingThrottle(1000)
.flatMap(batch => {
batch = batch.map(x => x*2); //this should be an async API call returning Bacon.fromPromise(...)
return Bacon.fromArray(batch);
})
// .bufferWithTime(1000)//one thang per interval
.onValue(val => $('#log').append(val));
for (var i=0; i<10; i++) {
stream.push(i);
}