1 /** PURE_IMPORTS_START tslib,_Subscription,_innerSubscribe PURE_IMPORTS_END */
2 import * as tslib_1 from "tslib";
3 import { Subscription } from '../Subscription';
4 import { SimpleOuterSubscriber, innerSubscribe, SimpleInnerSubscriber } from '../innerSubscribe';
5 export function bufferWhen(closingSelector) {
6 return function (source) {
7 return source.lift(new BufferWhenOperator(closingSelector));
10 var BufferWhenOperator = /*@__PURE__*/ (function () {
11 function BufferWhenOperator(closingSelector) {
12 this.closingSelector = closingSelector;
14 BufferWhenOperator.prototype.call = function (subscriber, source) {
15 return source.subscribe(new BufferWhenSubscriber(subscriber, this.closingSelector));
17 return BufferWhenOperator;
19 var BufferWhenSubscriber = /*@__PURE__*/ (function (_super) {
20 tslib_1.__extends(BufferWhenSubscriber, _super);
21 function BufferWhenSubscriber(destination, closingSelector) {
22 var _this = _super.call(this, destination) || this;
23 _this.closingSelector = closingSelector;
24 _this.subscribing = false;
28 BufferWhenSubscriber.prototype._next = function (value) {
29 this.buffer.push(value);
31 BufferWhenSubscriber.prototype._complete = function () {
32 var buffer = this.buffer;
34 this.destination.next(buffer);
36 _super.prototype._complete.call(this);
38 BufferWhenSubscriber.prototype._unsubscribe = function () {
39 this.buffer = undefined;
40 this.subscribing = false;
42 BufferWhenSubscriber.prototype.notifyNext = function () {
45 BufferWhenSubscriber.prototype.notifyComplete = function () {
46 if (this.subscribing) {
53 BufferWhenSubscriber.prototype.openBuffer = function () {
54 var closingSubscription = this.closingSubscription;
55 if (closingSubscription) {
56 this.remove(closingSubscription);
57 closingSubscription.unsubscribe();
59 var buffer = this.buffer;
61 this.destination.next(buffer);
66 var closingSelector = this.closingSelector;
67 closingNotifier = closingSelector();
70 return this.error(err);
72 closingSubscription = new Subscription();
73 this.closingSubscription = closingSubscription;
74 this.add(closingSubscription);
75 this.subscribing = true;
76 closingSubscription.add(innerSubscribe(closingNotifier, new SimpleInnerSubscriber(this)));
77 this.subscribing = false;
79 return BufferWhenSubscriber;
80 }(SimpleOuterSubscriber));
81 //# sourceMappingURL=bufferWhen.js.map