It is a quite common to need a Observable that ticks periodically, for instance every second or every miliseconds. We'll learn about operators interval () and timer (), both of which is similar to SetInterval () in JavaScript.
Interval (Period):
You can create interval () function by own:
varFoo =Rx.Observable.create (function (Observe) {vari =0; SetInterval (function () {observe.next (i); I++; }, +);}) Foo.subscribe (function (x) {Console.log ('Next'+x);}, function (err) {Console.log ('Error'+err);}, function () {Console.log (' Done');});
Pre
var foo = Rx.Observable.interval (+); Foo.subscribe (function (x) { Console.log ( " + x);}, function (err) { console.log (' + ERR);}, function () { console.log ('done');});
Timer (delay/date, period):
varFoo = Rx.Observable.timer ( the, +);//After 3 second delayvarDate =NewDate (NewDate (). GetTime () + the);varFoo = Rx.Observable.timer (date, +);//accept a Date objectFoo.subscribe (function (x) {Console.log ('Next'+x);}, function (err) {Console.log ('Error'+err);}, function () {Console.log (' Done');});
[RxJS] Creation Operators:interval and Timer