Learn RxJS
Search…
timeInterval

signature: timeInterval(scheduler: *): Observable<TimeInterval<any>> | WebSocketSubject<T> | Observable<T>

Convert an Observable that emits items into one that emits indications of the amount of time elapsed between those emissions

Examples

Example 1: Time between mouse clicks
1
// RxJS v6+
2
import { fromEvent } from 'rxjs';
3
import { timeInterval, tap } from 'rxjs/operators';
4
5
fromEvent(document, 'mousedown')
6
.pipe(timeInterval(), tap(console.log))
7
.subscribe(
8
i =>
9
(document.body.innerText = `milliseconds since last click: ${i.interval}`)
10
);
Copied!

Additional Resources

Last modified 1yr ago