Timer
create an Observable that emits a particular item after a given delay
The Timer operator creates an Observable that emits one particular item after a span of time that you specify.
See Also
Language-Specific Information
RxGroovy timer
RxGroovy implements this operator as timer.
timer returns an Observable that emits a single number zero after a delay period you specify.
timer by default operates on the computation Scheduler, or you can override this by passing in a Scheduler as a final parameter.
- Javadoc:
timer(long,TimeUnit) - Javadoc:
timer(long,TimeUnit,Scheduler)
RxJava 1․x timer
RxJava implements this operator as timer.
timer returns an Observable that emits a single number zero after a delay period you specify.
timer by default operates on the computation Scheduler, or you can override this by passing in a Scheduler as a final parameter.
- Javadoc:
timer(long,TimeUnit) - Javadoc:
timer(long,TimeUnit,Scheduler)
RxJS timer
In RxJS there are two versions of the timer operator.
The first version of timer returns an Observable that emits a single item after a delay period you specify. You can specify the delay either as a Date object (which means, delay until that absolute moment) or as an integer (which means, delay that many milliseconds).
There is also a version of timer that returns an Observable that emits a single item after a specified delay, and then emits items periodically thereafter on a specified periodicity. In this way it behaves a bit more like the Interval operator.
Sample Code
var source = Rx.Observable.timer(200, 100)
.timeInterval()
.pluck('interval')
.take(3);
var subscription = source.subscribe(
function (x) {
console.log('Next: ' + x);
},
function (err) {
console.log('Error: ' + err);
},
function () {
console.log('Completed');
});
Next: 200 Next: 100 Next: 100 Completed
timer by default operates on the timeout Scheduler, or you can override this by passing in a Scheduler as a final parameter.
timer is found in each of the following distributions:
rx.all.jsrx.all.compat.js-
rx.time.js(requires eitherrx.jsorrx.compat.js) rx.lite.jsrx.lite.compat.js
RxPHP timer
RxPHP implements this operator as timer.
Returns an observable sequence that produces a value after dueTime has elapsed.
Sample Code
//from https://github.com/ReactiveX/RxPHP/blob/master/demo/timer/timer.php $source = \Rx\Observable::timer(200); $source->subscribe($createStdoutObserver());
Next value: 0 Complete!
© ReactiveX contributors
Licensed under the Apache License 2.0.
http://reactivex.io/documentation/operators/timer.html