Search code examples
angularrxjsoperatorssubscriptioncombinelatest

Angular combineLatest: How many subscriptions are allowed in combineLatest? Are there any restrictions on number of subscribtions?


I am currently using 7 subscriptions in combine latest. Will mostly need to use some more. So need to know if any restrictions on subscriptions that goes in combineLatest.


Solution

  • That's a fair question. It depends on how you use the observables in combineLatest. If you pass the observables as an array, it doesn't matter how many you use. At least in the current RxJs (6.5.4) version you can pass it as an array.

    combineLatest([obs1$, obs2$, obs3$, obs4$, obs5$, ..., ... ..., ...])
    

    But if you pass the observables as arguments, you will get a deprecation warning from the IDE (Typescript Compiler) because this is limited on older RxJS versions.

    See the old signature: Source: https://rxjs-dev.firebaseapp.com/api/index/function/combineLatest

    combineLatest(
       v1: O1, v2: O2, v3: O3, v4: O4, v5: O5, v6: O6, scheduler?: SchedulerLike
    ): Observable<[ObservedValueOf<O1>, ObservedValueOf<O2>, ObservedValueOf<O3>, ObservedValueOf<O4>, ObservedValueOf<O5>, ObservedValueOf<O6>]>
    

    Conclusion:

    If you use the new signature, there is no restriction.