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

bufferToggle

Buffers the source Observable values starting from an emission from openings and ending when the output of closingSelector emits.

Collects values from the past as an array. Starts collecting only when opening emits, and calls the closingSelector function to get an Observable that tells when to close the buffer.

Buffers values from the source by opening the buffer via signals from an Observable provided to openings, and closing and sending the buffers when a Subscribable or Promise returned by the closingSelector function emits.

Example

Every other second, emit the click events from the next 500ms

import { fromEvent, interval, bufferToggle, EMPTY } from 'rxjs';

const clicks = fromEvent(document, 'click');
const openings = interval(1000);
const buffered = clicks.pipe(bufferToggle(openings, i =>
  i % 2 ? interval(500) : EMPTY
));
buffered.subscribe(x => console.log(x));
function bufferToggle<T, O>(openings: ObservableInput<O>, closingSelector: (value: O) => ObservableInput<any>): OperatorFunction<T, T[]>;
§
bufferToggle<T, O>(openings: ObservableInput<O>, closingSelector: (value: O) => ObservableInput<any>): OperatorFunction<T, T[]>
[src]

§Type Parameters

§Parameters

§

A Subscribable or Promise of notifications to start new buffers.

§
closingSelector: (value: O) => ObservableInput<any>
[src]

A function that takes the value emitted by the openings observable and returns a Subscribable or Promise, which, when it emits, signals that the associated buffer should be emitted and cleared.

§Return Type

§

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