Javatpoint Logo
Javatpoint Logo

RxJS throttle() Filtering Operator

RxJS throttle() operator is a filtering operator that emits a value from the source observable, then ignores subsequent source values for a specific duration determined by another observable, then repeats this process. It is similar to the throttleTime() operator, but the silencing duration is determined by a second Observable.

In other words, we can say that the RxJS throttle() operator provides the output and ignores values from the source observable for the time determined by the input function taken as an argument. This same process will be repeated after completing the first process.

Syntax:

Following is the syntax of the RxJS throttle() operator:

Or

Parameter Explanation

  • durationSelector: The durationSelector is an argument that specifies an observable or Promise that will ignore values from the values emitted from the source observable.
  • config: It specifies a configuration object used to define leading and trailing behavior. Defaults to { leading: true, trailing: false }. It is an optional argument. Its default value is defaultThrottleConfig.

Return value

The RxJS throttle() operator's return value is observable that performs the throttle operation to limit the source's rate of emissions.

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

Example 1 (Throttle for a specific time, based on second observable)

Output:

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

RxJS throttle() Filtering Operator

In the above example, you can see that it throttles for 2 seconds, and emits the latest value.

Example 2 (Throttle with promise)

Output:

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

RxJS throttle() Filtering Operator
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