You are on page 1of 2

25/08/2020 RxJS - timer

timer 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>

Parameters

Optional. Default is 0.


dueTime The initial delay time specified as a Date object or as an integer
denoting milliseconds to wait before emitting the first value of 0`.

Optional. Default is undefined.


periodOrScheduler
The period of time between emissions of the subsequent numbers.

Optional. Default is undefined.


scheduler The SchedulerLike to use for scheduling the emission of values, and
providing a notion of "time".

Returns

Observable<number>: An Observable that emits a 0 after the dueTime and ever increasing numbers after

each period of time thereafter.

Description

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

https://rxjs-dev.firebaseapp.com/api/index/function/timer 1/2
25/08/2020 RxJS - timer

specified dueTime. The initial delay may be a Date. By default, this operator uses
the asyncSchedulerLike 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.

Examples

Emits ascending numbers, one every second (1000ms), starting after 3


seconds

import { timer } from 'rxjs';

const numbers = timer(3000, 1000);


numbers.subscribe(x => console.log(x));

Emits one number after five seconds

import { timer } from 'rxjs';

const numbers = timer(5000);


numbers.subscribe(x => console.log(x));

https://rxjs-dev.firebaseapp.com/api/index/function/timer 2/2

You might also like