// RxJS v6+import { interval } from'rxjs';import { sample } from'rxjs/operators';//emit value every 1sconstsource=interval(1000);//sample last emitted value from source every 2sconstexample=source.pipe(sample(interval(2000)));//output: 2..4..6..8..constsubscribe=example.subscribe(val =>console.log(val));
// RxJS v6+import { interval, zip, from } from'rxjs';import { sample } from'rxjs/operators';constsource=zip(//emit 'Joe', 'Frank' and 'Bob' in sequencefrom(['Joe','Frank','Bob']),//emit value every 2sinterval(2000));//sample last emitted value from source every 2.5sconstexample=source.pipe(sample(interval(2500)));//output: ["Joe", 0]...["Frank", 1]...........constsubscribe=example.subscribe(val =>console.log(val));