UNPKG

@acutmore/rxjs

Version:

Reactive Extensions for modern JavaScript

121 lines 4.42 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var subscribeToResult_1 = require("../util/subscribeToResult"); var OuterSubscriber_1 = require("../OuterSubscriber"); var PausableBufferedSubscriber = /** @class */ (function (_super) { __extends(PausableBufferedSubscriber, _super); function PausableBufferedSubscriber(destination, pauser) { var _this = _super.call(this, destination) || this; _this.destination = destination; _this.pauser = pauser; _this.srcCompleted = false; _this.srcErrored = false; _this.srcError = undefined; _this.pauserCompleted = false; _this.flowing = false; _this.buffer = []; _this.draining = false; _this.add(subscribeToResult_1.subscribeToResult(_this, pauser)); return _this; } PausableBufferedSubscriber.prototype._next = function (value) { if (this.flowing) { this.destination.next(value); } else { var buffer = this.buffer; buffer[buffer.length] = value; } }; PausableBufferedSubscriber.prototype.__drain = function () { var buffer = this.buffer; while (buffer.length > 0) { this.destination.next(buffer.shift()); } }; PausableBufferedSubscriber.prototype.drainQueue = function () { if (this.draining) { return; } this.draining = true; try { this.__drain(); } finally { this.draining = false; } }; PausableBufferedSubscriber.prototype.notifyNext = function (outerValue, flowing, outerIndex, innerIndex, innerSub) { if (flowing === this.flowing) { return; } this.flowing = flowing; if (flowing) { this.drainQueue(); if (this.srcCompleted) { _super.prototype._complete.call(this); } if (this.srcErrored) { _super.prototype._error.call(this, this.srcError); } } }; PausableBufferedSubscriber.prototype._complete = function () { this.srcCompleted = true; if (this.buffer.length === 0 || this.pauserCompleted) { this.drainQueue(); _super.prototype._complete.call(this); } }; PausableBufferedSubscriber.prototype.notifyComplete = function (innerSub) { this.pauserCompleted = true; this.remove(innerSub); if (this.srcCompleted) { this.drainQueue(); this.destination.complete(); } if (this.srcErrored) { this.drainQueue(); _super.prototype._error.call(this, this.srcError); } }; PausableBufferedSubscriber.prototype._error = function (err) { this.srcErrored = true; this.srcError = err; if (this.buffer.length === 0 || this.pauserCompleted) { this.drainQueue(); _super.prototype._error.call(this, err); } }; PausableBufferedSubscriber.prototype.notifyError = function (err) { this.drainQueue(); _super.prototype._error.call(this, err); }; return PausableBufferedSubscriber; }(OuterSubscriber_1.OuterSubscriber)); var PausableBufferedOperator = /** @class */ (function () { function PausableBufferedOperator(pauser) { this.pauser = pauser; } PausableBufferedOperator.prototype.call = function (subscriber, source) { return source.subscribe(new PausableBufferedSubscriber(subscriber, this.pauser)); }; return PausableBufferedOperator; }()); function pausableBuffered(pauser) { return function pausableBufferedOperatorFunction(source) { return source.lift(new PausableBufferedOperator(pauser)); }; } exports.pausableBuffered = pausableBuffered; //# sourceMappingURL=pausableBuffered.js.map