bufferWhen.js 1.3 KB

123456789101112131415161718192021222324252627
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.bufferWhen = void 0;
  4. var lift_1 = require("../util/lift");
  5. var noop_1 = require("../util/noop");
  6. var OperatorSubscriber_1 = require("./OperatorSubscriber");
  7. var innerFrom_1 = require("../observable/innerFrom");
  8. function bufferWhen(closingSelector) {
  9. return lift_1.operate(function (source, subscriber) {
  10. var buffer = null;
  11. var closingSubscriber = null;
  12. var openBuffer = function () {
  13. closingSubscriber === null || closingSubscriber === void 0 ? void 0 : closingSubscriber.unsubscribe();
  14. var b = buffer;
  15. buffer = [];
  16. b && subscriber.next(b);
  17. innerFrom_1.innerFrom(closingSelector()).subscribe((closingSubscriber = OperatorSubscriber_1.createOperatorSubscriber(subscriber, openBuffer, noop_1.noop)));
  18. };
  19. openBuffer();
  20. source.subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, function (value) { return buffer === null || buffer === void 0 ? void 0 : buffer.push(value); }, function () {
  21. buffer && subscriber.next(buffer);
  22. subscriber.complete();
  23. }, undefined, function () { return (buffer = closingSubscriber = null); }));
  24. });
  25. }
  26. exports.bufferWhen = bufferWhen;
  27. //# sourceMappingURL=bufferWhen.js.map