Mastering Reactive JavaScript
上QQ阅读APP看书,第一时间看更新

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.