I want to execute tap() only when i get the first emitted value
Something like:
Observable
.pipe(
tap(() => { /* execute only when I get th
You can share() your main Observable like below:
import { timer, of, BehaviorSubject, interval } from 'rxjs';
import { tap, mapTo, share, shareReplay, } from 'rxjs/operators';
const source$ = timer(1000)
.pipe(
tap((v) => console.log('SIDE EFFECT')),
mapTo('RESULT')
)
const sharedSource$ = source$.pipe(share());
// or shareReplay(1) if you want to ensure every subscriber get the last value event if they will subscribe later;
sharedSource$.subscribe(console.log);
sharedSource$.subscribe(console.log);
sharedSource$.subscribe(console.log);
sharedSource$.subscribe(console.log);
sharedSource$.subscribe(console.log);
sharedSource$.subscribe(console.log);
sharedSource$.subscribe(console.log);
https://stackblitz.com/edit/typescript-qpnbkm?embed=1&file=index.ts
This is an example like in learn-rxjs