( StackBlitz )
// RxJS v6+
import { interval } from 'rxjs';
import { throttleTime } from 'rxjs/operators';
// emit value every 1 second
const source = interval(1000);
/*
emit the first value, then ignore for 5 seconds. repeat...
*/
const example = source.pipe(throttleTime(5000));
// output: 0...6...12
const subscribe = example.subscribe(val => console.log(val));
( StackBlitz )
// RxJS v6+
import { interval, asyncScheduler } from 'rxjs';
import { throttleTime } from 'rxjs/operators';
const source = interval(1000);
/*
emit the first value, then ignore for 5 seconds. repeat...
*/
const example = source.pipe(
throttleTime(5000, asyncScheduler, { trailing: true })
);
// output: 5...11...17
const subscribe = example.subscribe(val => console.log(val));
- throttleTime 📰 - Official docs
- throttleTime - In Depth Dev Reference
- Filtering operator: throttle and throttleTime 🎥 💵 - André Staltz
- Time based operators comparison
📁 Source Code: https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/throttleTime.ts