Consider two observables emitting values at different times combined with combineLatest. What will the subscriber receive?
import { combineLatest, timer } from 'rxjs'; import { map } from 'rxjs/operators'; const obs1 = timer(0, 100).pipe(map(x => `A${x}`)); const obs2 = timer(50, 100).pipe(map(x => `B${x}`)); combineLatest([obs1, obs2]).subscribe(values => console.log(values));
Remember, combineLatest waits for all observables to emit at least once, then emits on any new emission.
combineLatest emits an array of the latest values from each observable whenever any observable emits after all have emitted once.
Given two observables combined with forkJoin, what will the subscriber receive?
import { forkJoin, of } from 'rxjs'; import { delay } from 'rxjs/operators'; const obs1 = of('X').pipe(delay(100)); const obs2 = of('Y').pipe(delay(200)); forkJoin([obs1, obs2]).subscribe(values => console.log(values));
forkJoin waits for all observables to complete and emits once.
forkJoin emits an array of the last emitted values from each observable only after all observables complete.
Identify the correct import and usage of combineLatest from RxJS in Angular.
Check the correct import path and argument format for combineLatest.
combineLatest is imported from 'rxjs' and takes an array of observables.
Given this code, why does forkJoin never emit?
import { forkJoin, interval, of } from 'rxjs'; const obs1 = of('done'); const obs2 = interval(1000); forkJoin([obs1, obs2]).subscribe(console.log);
Think about when forkJoin emits values.
forkJoin waits for all observables to complete. interval never completes, so forkJoin never emits.
Which statement best describes when to use combineLatest versus forkJoin?
Think about emission timing and completion requirements.
combineLatest emits whenever any source emits after all have emitted once. forkJoin waits for all to complete and emits once.