function
stable
Buffers the source Observable values starting from an emission from openings
and ending when the output of closingSelector
emits.
bufferToggle<T, O>(openings: SubscribableOrPromise<O>, closingSelector: (value: O) => SubscribableOrPromise<any>): OperatorFunction<T, T[]>
openings | A Subscribable or Promise of notifications to start new buffers. |
closingSelector | A function that takes the value emitted by the |
OperatorFunction<T, T[]>
: An observable of arrays of buffered values.
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.
Every other second, emit the click events from the next 500ms
import { fromEvent, interval, EMPTY } from 'rxjs'; import { bufferToggle } from 'rxjs/operators'; 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));
© 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/bufferToggle