UNPKG

1.84 kBTypeScriptView Raw
1import { OperatorFunction, ObservableInput } from '../types';
2/**
3 * Buffers the source Observable values starting from an emission from
4 * `openings` and ending when the output of `closingSelector` emits.
5 *
6 * <span class="informal">Collects values from the past as an array. Starts
7 * collecting only when `opening` emits, and calls the `closingSelector`
8 * function to get an Observable that tells when to close the buffer.</span>
9 *
10 * ![](bufferToggle.png)
11 *
12 * Buffers values from the source by opening the buffer via signals from an
13 * Observable provided to `openings`, and closing and sending the buffers when
14 * a Subscribable or Promise returned by the `closingSelector` function emits.
15 *
16 * ## Example
17 *
18 * Every other second, emit the click events from the next 500ms
19 *
20 * ```ts
21 * import { fromEvent, interval, bufferToggle, EMPTY } from 'rxjs';
22 *
23 * const clicks = fromEvent(document, 'click');
24 * const openings = interval(1000);
25 * const buffered = clicks.pipe(bufferToggle(openings, i =>
26 * i % 2 ? interval(500) : EMPTY
27 * ));
28 * buffered.subscribe(x => console.log(x));
29 * ```
30 *
31 * @see {@link buffer}
32 * @see {@link bufferCount}
33 * @see {@link bufferTime}
34 * @see {@link bufferWhen}
35 * @see {@link windowToggle}
36 *
37 * @param openings A Subscribable or Promise of notifications to start new
38 * buffers.
39 * @param closingSelector A function that takes
40 * the value emitted by the `openings` observable and returns a Subscribable or Promise,
41 * which, when it emits, signals that the associated buffer should be emitted
42 * and cleared.
43 * @return A function that returns an Observable of arrays of buffered values.
44 */
45export declare function bufferToggle<T, O>(openings: ObservableInput<O>, closingSelector: (value: O) => ObservableInput<any>): OperatorFunction<T, T[]>;
46//# sourceMappingURL=bufferToggle.d.ts.map
\No newline at end of file