Skip to content

Latest commit

 

History

History
44 lines (31 loc) · 1.66 KB

File metadata and controls

44 lines (31 loc) · 1.66 KB

timer

####signature: timer(initialDelay: number | Date, period: number, scheduler: Scheduler): Observable

Description

TL;DR: After given duration, emit numbers in sequence every specified duration

Description coming soon...

Examples

Example 1: timer emits 1 value then completes

( jsBin | jsFiddle )

//emit 0 after 1 second then complete, since no second argument is supplied
const source = Rx.Observable.timer(1000);
//output: 0
const subscribe = source.subscribe(val => console.log(val));
Example 2: timer emits after 1 second, then every 2 seconds

( jsBin | jsFiddle )

/*
  timer takes a second argument, how often to emit subsequent values
  in this case we will emit first value after 1 second and subsequent
  values every 2 seconds after
*/
const source = Rx.Observable.timer(1000, 2000);
//output: 0,1,2,3,4,5......
const subscribe = source.subscribe(val => console.log(val));

Additional Resources


📁 Source Code: https://github.com/ReactiveX/rxjs/blob/master/src/observable/TimerObservable.ts