sampleTime
operator emits the most recent values in the final of the indicated period.
import { concat, of } from 'rxjs';
import { sampleTime, delay } from 'rxjs/operators';
const source$ = concat(
of('a').pipe(delay(1000)),
of('b').pipe(delay(500)),
of('c').pipe(delay(2000)),
of('d').pipe(delay(3000)),
of('e').pipe(delay(2000)),
);
const result$ = source$.pipe(sampleTime(2000));
Click the page to emit events
import { fromEvent } from 'rxjs';
import { sampleTime } from 'rxjs/operators';
const source$ = fromEvent(document, 'click');
const result$ = source$.pipe(sampleTime(1000));
Official Doc: rxjs.sampleTime