const require_rolldown_runtime = require('../../../../../../../../../_virtual/rolldown_runtime.js');
const require_noop$1 = require('../util/noop.js');
const require_lift$1 = require('../util/lift.js');
const require_OperatorSubscriber$1 = require('./OperatorSubscriber.js');
const require_innerFrom$1 = require('../observable/innerFrom.js');

//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/cjs/internal/operators/bufferWhen.js
var require_bufferWhen = /* @__PURE__ */ require_rolldown_runtime.__commonJS({ "../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/cjs/internal/operators/bufferWhen.js": ((exports) => {
	Object.defineProperty(exports, "__esModule", { value: true });
	var lift_1 = require_lift$1.require_lift();
	var noop_1 = require_noop$1.require_noop();
	var OperatorSubscriber_1 = require_OperatorSubscriber$1.require_OperatorSubscriber();
	var innerFrom_1 = require_innerFrom$1.require_innerFrom();
	function bufferWhen(closingSelector) {
		return lift_1.operate(function(source, subscriber) {
			var buffer = null;
			var closingSubscriber = null;
			var openBuffer = function() {
				closingSubscriber === null || closingSubscriber === void 0 || closingSubscriber.unsubscribe();
				var b = buffer;
				buffer = [];
				b && subscriber.next(b);
				innerFrom_1.innerFrom(closingSelector()).subscribe(closingSubscriber = OperatorSubscriber_1.createOperatorSubscriber(subscriber, openBuffer, noop_1.noop));
			};
			openBuffer();
			source.subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, function(value) {
				return buffer === null || buffer === void 0 ? void 0 : buffer.push(value);
			}, function() {
				buffer && subscriber.next(buffer);
				subscriber.complete();
			}, void 0, function() {
				return buffer = closingSubscriber = null;
			}));
		});
	}
	exports.bufferWhen = bufferWhen;
}) });

//#endregion
Object.defineProperty(exports, 'default', {
  enumerable: true,
  get: function () {
    return require_bufferWhen();
  }
});