1 /** PURE_IMPORTS_START tslib,_Subscription,_OuterSubscriber,_util_subscribeToResult PURE_IMPORTS_END */
2 import * as tslib_1 from "tslib";
3 import { Subscription } from '../Subscription';
4 import { OuterSubscriber } from '../OuterSubscriber';
5 import { subscribeToResult } from '../util/subscribeToResult';
6 export function bufferWhen(closingSelector) {
7 return function (source) {
8 return source.lift(new BufferWhenOperator(closingSelector));
11 var BufferWhenOperator = /*@__PURE__*/ (function () {
12 function BufferWhenOperator(closingSelector) {
13 this.closingSelector = closingSelector;
15 BufferWhenOperator.prototype.call = function (subscriber, source) {
16 return source.subscribe(new BufferWhenSubscriber(subscriber, this.closingSelector));
18 return BufferWhenOperator;
20 var BufferWhenSubscriber = /*@__PURE__*/ (function (_super) {
21 tslib_1.__extends(BufferWhenSubscriber, _super);
22 function BufferWhenSubscriber(destination, closingSelector) {
23 var _this = _super.call(this, destination) || this;
24 _this.closingSelector = closingSelector;
25 _this.subscribing = false;
29 BufferWhenSubscriber.prototype._next = function (value) {
30 this.buffer.push(value);
32 BufferWhenSubscriber.prototype._complete = function () {
33 var buffer = this.buffer;
35 this.destination.next(buffer);
37 _super.prototype._complete.call(this);
39 BufferWhenSubscriber.prototype._unsubscribe = function () {
41 this.subscribing = false;
43 BufferWhenSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
46 BufferWhenSubscriber.prototype.notifyComplete = function () {
47 if (this.subscribing) {
54 BufferWhenSubscriber.prototype.openBuffer = function () {
55 var closingSubscription = this.closingSubscription;
56 if (closingSubscription) {
57 this.remove(closingSubscription);
58 closingSubscription.unsubscribe();
60 var buffer = this.buffer;
62 this.destination.next(buffer);
67 var closingSelector = this.closingSelector;
68 closingNotifier = closingSelector();
71 return this.error(err);
73 closingSubscription = new Subscription();
74 this.closingSubscription = closingSubscription;
75 this.add(closingSubscription);
76 this.subscribing = true;
77 closingSubscription.add(subscribeToResult(this, closingNotifier));
78 this.subscribing = false;
80 return BufferWhenSubscriber;
82 //# sourceMappingURL=bufferWhen.js.map