Posts

Showing posts with the label rxjs6

Delay first 3 items by 1 second and the fourth by 4 seconds

Delay first 3 items by 1 second and the fourth by 4 seconds I'm trying to display the first 3 numbers each one delayed by 1 second and the fourth one by 4 seconds. Unfortunately, my code displays the four numbers by 1 second import { from, of, race, timer, interval } from 'rxjs'; import { groupBy, mergeMap, toArray, map,merge, reduce, concatMap, delay, concat, timeout, catchError, take } from 'rxjs/operators'; const obs$ = from([1,2,3]).pipe(concatMap(a => of(a).pipe(delay(1000)))); const obs2$ = of(4).pipe(delay(4000)); const result$ = obs$.pipe(merge(obs2$)); const subscribe = result$.subscribe(val => console.log(val)); It displays 1234| instead of 123----4| this question is entirely for learning rxjs as beginner and has been tested on https://stackblitz.com 1 Answer 1 METHOD 1 The merge operator subscribes to both observable ( obs$ and obs2$ ) at the same time . There...