Skip to content

combineLatestAll - Combine Latest Values of All Internal Observables

The combineLatestAll operator takes a Higher-order Observable (Observable of Observables), once all internal Observables have fired at least once, combines their latest values and outputs them as an array.

🔰 Basic Syntax and Usage

ts
import { interval, of } from 'rxjs';
import { combineLatestAll, take } from 'rxjs';

// Higher-order Observable with three internal Observables
const higherOrder$ = of(
  interval(1000).pipe(take(3)), // 0, 1, 2
  interval(500).pipe(take(4)),  // 0, 1, 2, 3
  interval(2000).pipe(take(2))  // 0, 1
);

// Combine latest values once all internal Observables have fired at least once
higherOrder$
  .pipe(combineLatestAll())
  .subscribe(values => console.log(values));

// Output:
// [1, 3, 0] ← When all have fired at least once (after 2 seconds)
// [2, 3, 0] ← 1st Observable fires 2 (after 3 seconds)
// [2, 3, 1] ← 3rd Observable fires 1 (after 4 seconds)
  • Collects internal Observables when Higher-order Observable completes
  • Once all internal Observables have fired at least once, starts combining
  • Whenever any internal Observable emits a value, combines all latest values and outputs

🌐 RxJS Official Documentation - combineLatestAll

💡 Typical Usage Patterns

  • Combine latest results of multiple API calls
  • Synchronize latest values of multiple form inputs
  • Integrate multiple real-time data sources

While combineLatestAll is primarily used for flattening Higher-order Observables, use the Creation Function combineLatest for normal multi-Observable combinations.

ts
import { combineLatest, interval } from 'rxjs';

// Creation Function version (more common usage)
const combined$ = combineLatest([
  interval(1000),
  interval(500),
  interval(2000)
]);

combined$.subscribe(console.log);

See Chapter 3: Creation Functions - combineLatest.

OperatorDescription
mergeAllSubscribe to all internal Observables in parallel
concatAllSubscribe to internal Observables in order
switchAllSwitch to new internal Observable
zipAllPair values in corresponding order from each internal Observable

⚠️ Important Notes

Higher-order Observable Must Complete

combineLatestAll waits to collect internal Observables until the Higher-order Observable (outer Observable) completes.

❌ Nothing output because Higher-order Observable doesn't complete

ts
interval(1000).pipe(
  map(() => of(1, 2, 3)),
  combineLatestAll()
).subscribe(console.log); // Nothing output

✅ Complete with take

ts
interval(1000).pipe(
  take(3), // Complete after 3
  map(() => of(1, 2, 3)),
  combineLatestAll()
).subscribe(console.log);

All Internal Observables Must Fire at Least Once

No values will be output until all internal Observables have fired at least once.

ts
import { of, NEVER } from 'rxjs';
import { combineLatestAll } from 'rxjs';

// Nothing output if even one internal Observable never fires
of(
  of(1, 2, 3),
  NEVER // Never fires
).pipe(
  combineLatestAll()
).subscribe(console.log); // Nothing output

Memory Usage

Note memory usage if there are many internal Observables, since latest values of all internal Observables are kept in memory.

Released under the CC-BY-4.0 license.