Skip to content

Latest commit

 

History

History
41 lines (27 loc) · 1.21 KB

timeinterval.md

File metadata and controls

41 lines (27 loc) · 1.21 KB

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

Ultimate RxJS

Examples

Example 1: Time between mouse clicks

( StackBlitz )

// RxJS v6+
import { fromEvent } from 'rxjs';
import { timeInterval, tap } from 'rxjs/operators';

fromEvent(document, 'mousedown')
  .pipe(timeInterval(), tap(console.log))
  .subscribe(
    i =>
      (document.body.innerText = `milliseconds since last click: ${i.interval}`)
  );

Related Recipes

Additional Resources


📁 Source Code: https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/timeInterval.ts