6155504921468bec6e0e97f3ae059ba8d5cd4f3bc6c5439eb80f1f810f14ef630872f4829d7f16a616fc549d474c562ffe344b4477529ac8d7538bbf0c4f81 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { ObservableInput, OperatorFunction } from '../types';
  2. /**
  3. * Buffers the source Observable values, using a factory function of closing
  4. * Observables to determine when to close, emit, and reset the buffer.
  5. *
  6. * <span class="informal">Collects values from the past as an array. When it
  7. * starts collecting values, it calls a function that returns an Observable that
  8. * tells when to close the buffer and restart collecting.</span>
  9. *
  10. * ![](bufferWhen.svg)
  11. *
  12. * Opens a buffer immediately, then closes the buffer when the observable
  13. * returned by calling `closingSelector` function emits a value. When it closes
  14. * the buffer, it immediately opens a new buffer and repeats the process.
  15. *
  16. * ## Example
  17. *
  18. * Emit an array of the last clicks every [1-5] random seconds
  19. *
  20. * ```ts
  21. * import { fromEvent, bufferWhen, interval } from 'rxjs';
  22. *
  23. * const clicks = fromEvent(document, 'click');
  24. * const buffered = clicks.pipe(
  25. * bufferWhen(() => interval(1000 + Math.random() * 4000))
  26. * );
  27. * buffered.subscribe(x => console.log(x));
  28. * ```
  29. *
  30. * @see {@link buffer}
  31. * @see {@link bufferCount}
  32. * @see {@link bufferTime}
  33. * @see {@link bufferToggle}
  34. * @see {@link windowWhen}
  35. *
  36. * @param closingSelector A function that takes no arguments and returns an
  37. * Observable that signals buffer closure.
  38. * @return A function that returns an Observable of arrays of buffered values.
  39. */
  40. export declare function bufferWhen<T>(closingSelector: () => ObservableInput<any>): OperatorFunction<T, T[]>;
  41. //# sourceMappingURL=bufferWhen.d.ts.map