RxJS & Reactive Programming
Angular combineLatest forkJoin
combineLatest emits whenever any source emits, giving the latest value from each. forkJoin waits for every source to complete and then emits their final values once — the RxJS equivalent of Promise.all.
What is combineLatest forkJoin in Angular?
combineLatest emits whenever any source emits, giving the latest value from each. forkJoin waits for every source to complete and then emits their final values once — the RxJS equivalent of Promise.all.
combineLatest forkJoin example
TypeScript
// parallel one-off requests — emits once when both finish
forkJoin({
job: this.api.getJob(id),
company: this.api.getCompany(companyId),
}).subscribe(({ job, company }) => { /* … */ });
// reactive filters — re-runs whenever any filter changes
combineLatest([this.city$, this.role$, this.page$]).pipe(
debounceTime(0),
switchMap(([city, role, page]) => this.api.search({ city, role, page }))
).subscribe(res => (this.results = res));Key points to remember
- forkJoin emits nothing if any source errors or never completes.
- combineLatest waits for every source to emit at least once before its first emission.
- Give filter streams an initial value, or combineLatest stays silent.
Common mistakes with combineLatest forkJoin
- Using forkJoin with a stream that never completes, so it never emits.
- combineLatest with a plain Subject that has not emitted, producing nothing.
Angular combineLatest forkJoin— Interview Questions & FAQs
What is the RxJS equivalent of Promise.all?+
forkJoin. It subscribes to all sources, waits for each to complete, and emits an array or object of their final values once.
