// RxJS v6+import { map, concatAll } from'rxjs/operators';import { of, interval } from'rxjs';//emit a value every 2 secondsconstsource=interval(2000);constexample=source.pipe(//for demonstration, add 10 to and return as observablemap(val =>of(val +10)),//merge values from inner observableconcatAll());//output: 'Example with Basic Observable 10', 'Example with Basic Observable 11'...constsubscribe=example.subscribe(val =>console.log('Example with Basic Observable:', val));
// RxJS v6+import { map, concatAll } from'rxjs/operators';import { interval } from'rxjs';//create and resolve basic promiseconstsamplePromise= val =>newPromise(resolve =>resolve(val));//emit a value every 2 secondsconstsource=interval(2000);constexample=source.pipe(map(val =>samplePromise(val)),//merge values from resolved promiseconcatAll());//output: 'Example with Promise 0', 'Example with Promise 1'...constsubscribe=example.subscribe(val =>console.log('Example with Promise:', val));
// RxJS v6+import { take, concatAll } from'rxjs/operators';import { interval, of } from'rxjs';constobs1=interval(1000).pipe(take(5));constobs2=interval(500).pipe(take(2));constobs3=interval(2000).pipe(take(1));//emit three observablesconstsource=of(obs1, obs2, obs3);//subscribe to each inner observable in order when previous completesconstexample=source.pipe(concatAll());/* output: 0,1,2,3,4,0,1,0 How it works... Subscribes to each inner observable and emit values, when complete subscribe to next obs1: 0,1,2,3,4 (complete) obs2: 0,1 (complete) obs3: 0 (complete)*/constsubscribe=example.subscribe(val =>console.log(val));