bufferWhen.js 1.1 KB

1234567891011121314151617181920212223
  1. import { operate } from '../util/lift';
  2. import { noop } from '../util/noop';
  3. import { createOperatorSubscriber } from './OperatorSubscriber';
  4. import { innerFrom } from '../observable/innerFrom';
  5. export function bufferWhen(closingSelector) {
  6. return operate(function (source, subscriber) {
  7. var buffer = null;
  8. var closingSubscriber = null;
  9. var openBuffer = function () {
  10. closingSubscriber === null || closingSubscriber === void 0 ? void 0 : closingSubscriber.unsubscribe();
  11. var b = buffer;
  12. buffer = [];
  13. b && subscriber.next(b);
  14. innerFrom(closingSelector()).subscribe((closingSubscriber = createOperatorSubscriber(subscriber, openBuffer, noop)));
  15. };
  16. openBuffer();
  17. source.subscribe(createOperatorSubscriber(subscriber, function (value) { return buffer === null || buffer === void 0 ? void 0 : buffer.push(value); }, function () {
  18. buffer && subscriber.next(buffer);
  19. subscriber.complete();
  20. }, undefined, function () { return (buffer = closingSubscriber = null); }));
  21. });
  22. }
  23. //# sourceMappingURL=bufferWhen.js.map