O'Reilly logo

Mastering Reactive JavaScript by Erich de Souza Oliveira

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating an observable using period of time

In the previous chapter, we discussed how to create timed sequences in bacon.js. In RxJS, we have two different methods to implement observables emitting values with a given interval. The first method is interval(). This method emits an infinite sequence of integers starting from one every x milliseconds; it has the following signature:

Rx.Observable.interval(interval, [scheduler]); 

The interval parameter is mandatory, and the second argument is optional:

  • interval: This is an integer number to be used as the interval between the values of this sequence
  • scheduler: This is used to generate the values

Run the following code:

Rx.Observable     .interval(1000)     .subscribe((i)=> console.log(i)); 

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required