I've got an Angular 2 app, which fetches a varying number of ids from a server, and then, for each id makes another REST call in a forkJoin.
However, the amount of ids can go up to a few hundreds, which might be problematic when suddenly making several hundred REST calls in parallel.
Is there a way of limiting the number of parallel calls when using RxJs and the forkJoin operator?
Onw way would be to use bufferCount:
Rx.Observable.from([1,2,3,4,5,6,7,8])
.bufferCount(3)
.concatMap(items => {
console.log('ConcatMap', items);
let tasks = items.map(item => Rx.Observable.timer(Math.random() * 1000).do(() => console.log(item, 'ready')));
return Rx.Observable.forkJoin(...tasks);
})
.subscribe()
<script src="https://npmcdn.com/@reactivex/[email protected]/dist/global/Rx.js"></script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With