Reputation: 14563
I have an array of payloads I want perform a couple async actions on each and then send to a server. I'm trying to do it like this:
Rx.Observable.from(payloads)
.flatMap(item => ... do something A something async, return modified payload)
.flatMap(item => ... do something B)
.flatMap(item => ... post to server)
.subscribe();
This works....
But it seems to do A for each payload all at once, then B for each payload all at once, then post each payload all at once.
With lists of potentially thousands of payloads. Is there any way to go through the payloads one at a time, one step at a time?
Upvotes: 1
Views: 69
Reputation: 9425
If they need to be done a->b->c for each payload:
Rx.Observable.from(payloads)
.concatMap(payload => doA())
.concatMap(resA => doB())
.concatMap(resB => doC())
.subscribe(console.log)
concatMap will wait until the previous emission completes before starting the next. This will limit your concurrency.
Upvotes: 2