Learn RxJS
Search…
throttleTime

signature: throttleTime(duration: number, scheduler: Scheduler, config: ThrottleConfig): Observable

Emit first value then ignore for specified duration

Examples

Example 1: Emit first value, ignore for 5s window
1
// RxJS v6+
2
import { interval } from 'rxjs';
3
import { throttleTime } from 'rxjs/operators';
4
5
// emit value every 1 second
6
const source = interval(1000);
7
/*
8
emit the first value, then ignore for 5 seconds. repeat...
9
*/
10
const example = source.pipe(throttleTime(5000));
11
// output: 0...6...12
12
const subscribe = example.subscribe(val => console.log(val));
Copied!
Example 2: Emit on trailing edge using config
1
// RxJS v6+
2
import { interval, asyncScheduler } from 'rxjs';
3
import { throttleTime } from 'rxjs/operators';
4
5
const source = interval(1000);
6
/*
7
emit the first value, then ignore for 5 seconds. repeat...
8
*/
9
const example = source.pipe(
10
throttleTime(5000, asyncScheduler, { trailing: true })
11
);
12
// output: 5...11...17
13
const subscribe = example.subscribe(val => console.log(val));
Copied!

Additional Resources

Last modified 6mo ago