function
stable
Buffers the source Observable values for a specific time period.
bufferTime<T>(bufferTimeSpan: number): OperatorFunction<T, T[]>
bufferTimeSpan | The amount of time to fill each buffer array. |
OperatorFunction<T, T[]>
: An observable of arrays of buffered values.
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.
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));
bufferTime(bufferTimeSpan: number, scheduler?: SchedulerLike): OperatorFunction<T, T[]>
bufferTimeSpan | Type: |
scheduler | Optional. Default is Type: |
OperatorFunction<T, T[]>
bufferTime(bufferTimeSpan: number, bufferCreationInterval: number | null | undefined, scheduler?: SchedulerLike): OperatorFunction<T, T[]>
bufferTimeSpan | Type: |
bufferCreationInterval | Type: |
scheduler | Optional. Default is Type: |
OperatorFunction<T, T[]>
bufferTime(bufferTimeSpan: number, bufferCreationInterval: number | null | undefined, maxBufferSize: number, scheduler?: SchedulerLike): OperatorFunction<T, T[]>
bufferTimeSpan | Type: |
bufferCreationInterval | Type: |
maxBufferSize | Type: |
scheduler | Optional. Default is Type: |
OperatorFunction<T, T[]>
© 2015–2018 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