- RxJS Tutorial
- RxJS - Home
- RxJS - Overview
- RxJS - Environment Setup
- RxJS - Latest Updates
- RxJS - Observables
- RxJS - Operators
- RxJS - Working with Subscription
- RxJS - Working with Subjects
- RxJS - Working with Scheduler
- RxJS - Working with RxJS & Angular
- RxJS - Working with RxJS & ReactJS
- RxJS Useful Resources
- RxJS - Quick Guide
- RxJS - Useful Resources
- RxJS - Discussion
RxJS - Transformation Operator bufferTime
This is similar to bufferCount, so here, it will collect the values from the observable on which it is called and emit the bufferTimeSpan is done. It takes in 1 argument, i.e., bufferTimeSpan.
Syntax
bufferTime(bufferTimeSpan: number): Observable
Parameters
bufferTimeSpan − The time to fill the buffer array.
Return value
An observable will be returned, that will have an array of buffered values.
Example
import { fromEvent } from 'rxjs'; import { bufferTime } from 'rxjs/operators'; let btn = document.getElementById("btnclick"); let btn_clicks = fromEvent(btn, 'click'); let buffered_array = btn_clicks.pipe(bufferTime(4000)); buffered_array.subscribe(arr => console.log(arr));
In the example the time used is 4seconds, So, bufferTime() operator will accumulate the clicks and after every 4 seconds will display them as shown below.
Output
Advertisements
To Continue Learning Please Login
Login with Google