Javatpoint Logo
Javatpoint Logo

RxJS interval() Creation Operator

RxJS interval() operator is a creation operator used to create an observable that emits a sequence of integers every time for the given time interval on a specified SchedulerLike. It emits incremented numbers periodically in time.

In other words, we can say that the RxJS interval() operator returns an observable that emits sequential numbers every specified interval of time.

It emits an infinite sequence of ascending integers, with a constant interval of time of your choosing between emissions.

Syntax:

Following is the syntax of the RxJS interval() creation operator:

Or

Or

Parameter Explanation

  • time: It specifies the time given in milliseconds.
  • period: It is used to specify the interval size in milliseconds (by default) or the time unit determined by the scheduler's clock. It is an optional argument. Its default value is 0.
  • scheduler: It is used to schedule the emission of values and provide a notion of "time." It is also an optional argument. Its default value is async.

Return value

The RxJS interval() operator returns an observable that emits a sequentially increasing number within the given interval of time.

Let us see some examples of the RxJS interval() operator to understand it clearly.

Example 1 (Emits ascending numbers infinite times)

Output:

After executing the above example, you will see the following result:

RxJS interval() Creation Operator

In the above example, you can see that it is emitting values infinite times until you stop the process by pressing the Ctrl + C button.

Example 2 (Emits ascending numbers up to a specific number)

Output:

After executing the above example, you will see the following result:

RxJS interval() Creation Operator

In the above example, you can see that it is emitting values only up to 8 numbers which we have specified earlier.


Next TopicRxJS Operators




Youtube For Videos Join Our Youtube Channel: Join Now

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA