Code coverage report for usr/local/google/home/trevj/src/uproxy-lib/build/dev/uproxy-lib/handler/aggregate.js

Statements: 96.15% (25 / 26)      Branches: 100% (2 / 2)      Functions: 87.5% (7 / 8)      Lines: 96.15% (25 / 26)      Ignored: none     

All files » usr/local/google/home/trevj/src/uproxy-lib/build/dev/uproxy-lib/handler/ » aggregate.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44      1 1 1 1 1 3 3           1 6 6 4   2 2 2       1 6 6 6 6   1   1     1   1 1   1  
/// <reference path='../../../third_party/typings/es6-promise/es6-promise.d.ts' />
// All handle calls get the same result for an aggregated collection of things
// in the queue.
var AggregateHandlerClass = (function () {
    function AggregateHandlerClass(aggregator_) {
        var _this = this;
        this.aggregator_ = aggregator_;
        this.resetNextPromise_ = function () {
            _this.nextAggregate_ = new Promise(function (F, R) {
                _this.fulfillNextFn_ = F;
            });
        };
        // Checks to see if the aggregator can now aggregate the inputs. Returns
        // true if the old |nextAggregate| has been fulfilled and a new
        // |nextAggregate| has been created.
        this.tryNext = function () {
            var result = _this.aggregator_.check();
            if (result === null) {
                return false;
            }
            _this.fulfillNextFn_(result);
            _this.resetNextPromise_();
            return true;
        };
        // The handle function for aggregating elements. Note that all handle calls
        // of values will get the same aggregated reult promise.
        this.handle = function (x) {
            _this.aggregator_.input(x);
            var currentPromise = _this.nextAggregate_;
            _this.tryNext();
            return currentPromise;
        };
        this.resetNextPromise_();
    }
    AggregateHandlerClass.prototype.nextAggregate = function () {
        return this.nextAggregate_;
    };
    return AggregateHandlerClass;
})();
function createAggregateHandler(aggregator) {
    return new AggregateHandlerClass(aggregator);
}
exports.createAggregateHandler = createAggregateHandler;