interval

signature: interval(period: number, scheduler: Scheduler): Observable

Emit numbers in sequence based on provided timeframe.

interval - 图1

Examples

Example 1: Emit sequence of values at 1 second interval

( jsBin |
jsFiddle )

  1. import { interval } from 'rxjs/observable/interval';
  2. //emit value in sequence every 1 second
  3. const source = interval(1000);
  4. //output: 0,1,2,3,4,5....
  5. const subscribe = source.subscribe(val => console.log(val));

Additional Resources


:file_folder: Source Code:
https://github.com/ReactiveX/rxjs/blob/master/src/internal/observable/interval.ts