Javatpoint Logo
Javatpoint Logo

RxJS bufferWhen() Transformation Operator

The RxJS bufferWhen() operator is a transformation operator buffers the data from the source Observable until the closingSelector function has closed the buffer. This collects values from the past as an array. When the value collection is started, it calls a function that returns an Observable, which decides when to close, emit and reset the buffer.

In other words, we can say that the RxJS bufferWhen() operator is used to buffer the source Observable values, using a factory function of closing Observables to specify when to close, emit, and reset the buffer.

The closingSelector function is responsible for closing the buffer.

Syntax:

Following is the syntax of the bufferTime() operator:

Parameter Explanation

closingSelector: It specifies a function that takes no arguments and returns an Observable that signals the buffer closure.

Return value

The bufferWhen () operator's return value is observable that will have an array of buffered values.

Let us see an example of bufferWhen () operator to understand it clearly.

Example (Emit buffer within a time interval)

Output:

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

RxJS bufferWhen() Transformation Operator

In the above example, you can see that it is emitting an array of the last clicks after every 5 seconds and will get reset and start again.


Next TopicRxJS Operators





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA