sample
operator accept a notifier
observable as argument,
that indicate when emits values from source observable
import { fromEvent, interval, range, of } from 'rxjs';
import { sample, concatMap, delay, mapTo, take } from 'rxjs/operators';
const source$ = range(0, 8).pipe(
concatMap((v) => of(v).pipe(delay(v * 500)))
)
const notifier$ = interval(1500).pipe(mapTo('💥'), take(9));
const result$ = source$.pipe(sample(notifier$));
click to the page to notify emit value
import { fromEvent, interval } from 'rxjs';
import { sample } from 'rxjs/operators';
const source$ = interval(1500);
const notifier$ = fromEvent(document, 'click');;
const result$ = source$.pipe(sample(notifier$));
Official Doc: rxjs.sample