Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

bufferCount

Buffers the source Observable values until the size hits the maximum bufferSize given.

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.

Examples

Emit the last two click events as an array

import { fromEvent, bufferCount } from 'rxjs';

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, bufferCount } from 'rxjs';

const clicks = fromEvent(document, 'click');
const buffered = clicks.pipe(bufferCount(2, 1));
buffered.subscribe(x => console.log(x));
function bufferCount<T>(bufferSize: number, startBufferEvery?: number | null): OperatorFunction<T, T[]>;
§
bufferCount<T>(bufferSize: number, startBufferEvery?: number | null): OperatorFunction<T, T[]>
[src]

§Type Parameters

§Parameters

§
bufferSize: number
[src]

The maximum size of the buffer emitted.

§
startBufferEvery?: number | null optional
[src]

§Return Type

§

A function that returns an Observable of arrays of buffered values.