bufferTime
function
stable
Buffers the source Observable values for a specific time period.
bufferTime<T>(bufferTimeSpan: number, ...otherArgs: any[]): OperatorFunction<T, T[]>
Parameters
bufferTimeSpan | The amount of time to fill each buffer array. |
otherArgs | Type: |
Returns
OperatorFunction<T, T[]>
: A function that returns an Observable of arrays of buffered values.
Description
Collects values from the past as an array, and emits those arrays periodically in time.
Buffers values from the source for a specific time duration bufferTimeSpan
. Unless the optional argument bufferCreationInterval
is given, it emits and resets the buffer every bufferTimeSpan
milliseconds. If bufferCreationInterval
is given, this operator opens the buffer every bufferCreationInterval
milliseconds and closes (emits and resets) the buffer every bufferTimeSpan
milliseconds. When the optional argument maxBufferSize
is specified, the buffer will be closed either after bufferTimeSpan
milliseconds or when it contains maxBufferSize
elements.
Examples
Every second, emit an array of the recent click events
import { fromEvent } from 'rxjs'; import { bufferTime } from 'rxjs/operators'; const clicks = fromEvent(document, 'click'); const buffered = clicks.pipe(bufferTime(1000)); buffered.subscribe(x => console.log(x));
Every 5 seconds, emit the click events from the next 2 seconds
import { fromEvent } from 'rxjs'; import { bufferTime } from 'rxjs/operators'; const clicks = fromEvent(document, 'click'); const buffered = clicks.pipe(bufferTime(2000, 5000)); buffered.subscribe(x => console.log(x));
Overloads
bufferTime(bufferTimeSpan: number, scheduler?: SchedulerLike): OperatorFunction<T, T[]>
Parameters
bufferTimeSpan | Type: |
scheduler | Optional. Default is Type: |
Returns
OperatorFunction<T, T[]>
bufferTime(bufferTimeSpan: number, bufferCreationInterval: number, scheduler?: SchedulerLike): OperatorFunction<T, T[]>
Parameters
bufferTimeSpan | Type: |
bufferCreationInterval | Type: |
scheduler | Optional. Default is Type: |
Returns
OperatorFunction<T, T[]>
bufferTime(bufferTimeSpan: number, bufferCreationInterval: number, maxBufferSize: number, scheduler?: SchedulerLike): OperatorFunction<T, T[]>
Parameters
bufferTimeSpan | Type: |
bufferCreationInterval | Type: |
maxBufferSize | Type: |
scheduler | Optional. Default is Type: |
Returns
OperatorFunction<T, T[]>
See Also
© 2015–2021 Google, Inc., Netflix, Inc., Microsoft Corp. and contributors.
Code licensed under an Apache-2.0 License. Documentation licensed under CC BY 4.0.
https://rxjs.dev/api/operators/bufferTime