ReactiveX
  1. Operators
  2. Creating
  3. Timer

Timer

create an Observable that emits a particular item after a given delay

Timer

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 implements this operator as timer.

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.

RxJava implements this operator as timer.

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.

In RxJS there are two versions of the timer operator.

timer

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).

timer

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.js
  • rx.all.compat.js
  • rx.time.js (requires either rx.js or rx.compat.js)
  • rx.lite.js
  • rx.lite.compat.js

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!
 

TBD

AltStyle によって変換されたページ (->オリジナル) /