ββββ
Example 1: timer emits 1 value then completes
( StackBlitz | jsBin | jsFiddle )
// RxJS v6+import { timer } from 'rxjs';β//emit 0 after 1 second then complete, since no second argument is suppliedconst source = timer(1000);//output: 0const subscribe = source.subscribe(val => console.log(val));
Example 2: timer emits after 1 second, then every 2 seconds
( StackBlitz | jsBin | jsFiddle )
// RxJS v6+import { timer } from 'rxjs';β/*timer takes a second argument, how often to emit subsequent valuesin this case we will emit first value after 1 second and subsequentvalues every 2 seconds after*/const source = timer(1000, 2000);//output: 0,1,2,3,4,5......const subscribe = source.subscribe(val => console.log(val));
βHTTP Pollingβ
βtimer π° - Official docs
βCreation operators: interval and timerβ
π₯ π΅ - AndrΓ© Staltz
βBuild your own timer operatorβ
π₯ - Kwinten Pisman
π Source Code: https://github.com/ReactiveX/rxjs/blob/master/src/internal/observable/timer.tsβ