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() 

http://jsfiddle.net/jdr9wuzy/


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -