javascript - Rate limiting with Bacon.JS -
i'm trying create rate limiting when accessing external api, using bacon.js
the rate limiting works fine, using bufferwithcount , bufferingthrottle results when flatmapped, not each batch @ time.
i've tries onend not seem triggered.
here's 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 async api call returning bacon.frompromise(...) return bacon.fromarray(batch); }) // .bufferwithtime(1000)//one thang per interval .onvalue(val => $('#log').append(val)); (var i=0; i<10; i++) { stream.push(i); }
you can use fold combine results , .end() cause bus end.
stream .bufferwithcount(2) .bufferingthrottle(1000) .flatmap(batch => { batch = batch.map(x => x*2); //this should async op return bacon.fromarray(batch); }) .fold([], (arr, val) => { return arr.concat(val) }) // .bufferwithtime(1000)//one thang per interval .onvalue(val => $('#log').append(val+"\n")); (var i=0; i<10; i++) { stream.push(i); } stream.end()
Comments
Post a Comment