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

Observables from an interval (interval)

We can create an observable from an interval; this is especially useful if you wish to execute repetitive tasks, and it can be used as a substitution for the setInterval() method. An EventStream created by the interval() method will never end; this method has the following signature:

Bacon.interval(intervalInMilliseconds); 

It receives only one parameter, that is the interval between the events in milliseconds, and it will emit an empty object as the event. Let's say you have run the following code:

Bacon     .interval(100)     .onValue((event)=>{         console.log(event);     }); 

If so, you will see the following output:

    {}    {}    {}    {}

It will keep printing an empty object until you kill the program.

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