// RxJS v6+import { of, timer } from'rxjs';import { debounce } from'rxjs/operators';//emit four stringsconstexample=of('WAIT','ONE','SECOND','Last will display');/* Only emit values after a second has passed between the last emission, throw away all other values*/constdebouncedExample=example.pipe(debounce(() =>timer(1000)));/* In this example, all values but the last will be omitted output: 'Last will display'*/constsubscribe=debouncedExample.subscribe(val =>console.log(val));
// RxJS v6+import { interval, timer } from'rxjs';import { debounce } from'rxjs/operators';//emit value every 1 second, ex. 0...1...2constinterval$=interval(1000);//raise the debounce time by 200ms each secondconstdebouncedInterval=interval$.pipe(debounce(val =>timer(val *200)));/* After 5 seconds, debounce time will be greater than interval time, all future values will be thrown away output: 0...1...2...3...4......(debounce time over 1s, no values emitted)*/constsubscribe=debouncedInterval.subscribe(val =>console.log(`Example Two: ${val}`));