function
stable
Buffers the source Observable values until the size hits the maximum bufferSize
given.
bufferCount<T>(bufferSize: number, startBufferEvery: number = null): OperatorFunction<T, T[]>
bufferSize | The maximum size of the buffer emitted. |
startBufferEvery | Optional. Default is Interval at which to start a new buffer. For example if |
OperatorFunction<T, T[]>
: An Observable of arrays of buffered values.
Collects values from the past as an array, and emits that array only when its size reaches bufferSize
.
Buffers a number of values from the source Observable by bufferSize
then emits the buffer and clears it, and starts a new buffer each startBufferEvery
values. If startBufferEvery
is not provided or is null
, then new buffers are started immediately at the start of the source and when each buffer closes and is emitted.
Emit the last two click events as an array
import { fromEvent } from 'rxjs'; import { bufferCount } from 'rxjs/operators'; const clicks = fromEvent(document, 'click'); const buffered = clicks.pipe(bufferCount(2)); buffered.subscribe(x => console.log(x));
On every click, emit the last two click events as an array
import { fromEvent } from 'rxjs'; import { bufferCount } from 'rxjs/operators'; const clicks = fromEvent(document, 'click'); const buffered = clicks.pipe(bufferCount(2, 1)); buffered.subscribe(x => console.log(x));
© 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/bufferCount