RxJS bufferTime() Transformation OperatorThe RxJS bufferTime() operator is a transformation operator similar to bufferCount() operator. It is used to buffer the emitted data of the originating Observable for a specific time period and collects values from the past as an array, and emits those arrays periodically in time. It takes mainly two types of arguments:
The unit for the time span is specified in milliseconds. Syntax:Following is the syntax of the bufferTime() operator: Parameter ExplanationbufferTimeSpan: It specifies the amount of time to fill each buffer array. Return valueThe bufferTime() operator's return value is an observable that will have an array of buffered values. Let us see some examples of bufferTime() operator to understand it clearly. Example 1Output: After executing the above example, you will see the following result: In the above example, you can see that a new number appeared every 2 seconds in the arrays that are emitted, while the rest of the emitted arrays are empty. Example 2 (Using bufferCreationInterval argument)Output: After executing the above example, you will see the following result: In the above example, we have set the buffer time interval for 2 second where the buffered data is emitted every second, and the buffer is created every second.
Next TopicRxJS Operators
|