Search code examples
typescriptdictionaryrxjsflatmapconcatmap

RxJS FlatMap and ConcatMap intermediate solution?


I have an application written in typescript using rxjs where im using flatMap to return a list of 5000 observables, but i don't want them all to be subscribed at the same time.

I tried to use concatMap but it lets my application very slow, since it process one by one in sequence.

Im interesed in creating something like a pool of 10 subscriptions where when one ends the other starts, this will keep only 10 subscriptions active at same time.

I imagine i can create a manual control of that but im interested in knowing if there is a better approach, using some other kind of map or strategy.


Solution

  • The tip of @cartant help me find a solution, for the code below you can use flatMap or mergeMap since they are the same.

    this.service.getData(id).flatMap(data => {
      return Observable.of(data);
    }, 10).do(value => {
      console.log(value);
    })
    

    This code is just for passing the idea how to use the concurrent parameter of flatMap/mergeMap. The number 10 is the concurrent parameter.