function
stable
Creates an Observable that starts emitting after an dueTime
and emits ever increasing numbers after each period
of time thereafter.
timer(dueTime: number | Date = 0, periodOrScheduler?: number | SchedulerLike, scheduler?: SchedulerLike): Observable<number>
dueTime | Optional. Default is The initial delay time specified as a Date object or as an integer denoting milliseconds to wait before emitting the first value of 0`. |
periodOrScheduler | Optional. Default is The period of time between emissions of the subsequent numbers. |
scheduler | Optional. Default is The |
Observable<number>
: An Observable that emits a 0
after the dueTime
and ever increasing numbers after each period
of time thereafter.
Its like interval
, but you can specify when should the emissions start.
timer
returns an Observable that emits an infinite sequence of ascending integers, with a constant interval of time, period
of your choosing between those emissions. The first emission happens after the specified dueTime
. The initial delay may be a Date
. By default, this operator uses the async
SchedulerLike
to provide a notion of time, but you may pass any SchedulerLike
to it. If period
is not specified, the output Observable emits only one value, 0
. Otherwise, it emits an infinite sequence.
import { timer } from 'rxjs'; const numbers = timer(3000, 1000); numbers.subscribe(x => console.log(x));
import { timer } from 'rxjs'; const numbers = timer(5000); numbers.subscribe(x => console.log(x));
© 2015–2018 Google, Inc., Netflix, Inc., Microsoft Corp. and contributors.
Code licensed under an Apache-2.0 License. Documentation licensed under CC BY 4.0.
https://rxjs.dev/api/index/function/timer