UNPKG

rxjs

Version:

Reactive Extensions for modern JavaScript

27 lines 1.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.bufferWhen = void 0; var lift_1 = require("../util/lift"); var noop_1 = require("../util/noop"); var OperatorSubscriber_1 = require("./OperatorSubscriber"); var innerFrom_1 = require("../observable/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 ? void 0 : closingSubscriber.unsubscribe(); var b = buffer; buffer = []; b && subscriber.next(b); innerFrom_1.innerFrom(closingSelector()).subscribe((closingSubscriber = new OperatorSubscriber_1.OperatorSubscriber(subscriber, openBuffer, noop_1.noop))); }; openBuffer(); source.subscribe(new OperatorSubscriber_1.OperatorSubscriber(subscriber, function (value) { return buffer === null || buffer === void 0 ? void 0 : buffer.push(value); }, function () { buffer && subscriber.next(buffer); subscriber.complete(); }, undefined, function () { return (buffer = closingSubscriber = null); })); }); } exports.bufferWhen = bufferWhen; //# sourceMappingURL=bufferWhen.js.map