interval
function stable
Creates an Observable that emits sequential numbers every specified interval of time, on a specified SchedulerLike.
interval(period: number = 0, scheduler: SchedulerLike = asyncScheduler): Observable<number>
Parameters
| period | Optional. Default is The interval size in milliseconds (by default) or the time unit determined by the scheduler's clock. |
| scheduler | Optional. Default is The |
Returns
Observable<number>: An Observable that emits a sequential number each time interval.
Description
Emits incremental numbers periodically in time.
interval returns an Observable that emits an infinite sequence of ascending integers, with a constant interval of time of your choosing between those emissions. The first emission is not sent immediately, but only after the first period has passed. By default, this operator uses the async SchedulerLike to provide a notion of time, but you may pass any SchedulerLike to it.
Example
Emits ascending numbers, one every second (1000ms) up to the number 3
import { interval } from 'rxjs';
import { take } from 'rxjs/operators';
const numbers = interval(1000);
const takeFourNumbers = numbers.pipe(take(4));
takeFourNumbers.subscribe(x => console.log('Next: ', x));
// Logs:
// Next: 0
// Next: 1
// Next: 2
// Next: 3 See Also
© 2015–2021 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/interval