/* automatically generated by JSCoverage - do not edit */
if (typeof _$jscoverage === 'undefined') _$jscoverage = {};
if (! _$jscoverage['promise.js']) {
  _$jscoverage['promise.js'] = [];
  _$jscoverage['promise.js'][1] = 0;
  _$jscoverage['promise.js'][4] = 0;
  _$jscoverage['promise.js'][48] = 0;
  _$jscoverage['promise.js'][49] = 0;
  _$jscoverage['promise.js'][55] = 0;
  _$jscoverage['promise.js'][56] = 0;
  _$jscoverage['promise.js'][57] = 0;
  _$jscoverage['promise.js'][60] = 0;
  _$jscoverage['promise.js'][61] = 0;
  _$jscoverage['promise.js'][73] = 0;
  _$jscoverage['promise.js'][74] = 0;
  _$jscoverage['promise.js'][75] = 0;
  _$jscoverage['promise.js'][77] = 0;
  _$jscoverage['promise.js'][80] = 0;
  _$jscoverage['promise.js'][90] = 0;
  _$jscoverage['promise.js'][91] = 0;
  _$jscoverage['promise.js'][92] = 0;
  _$jscoverage['promise.js'][94] = 0;
  _$jscoverage['promise.js'][100] = 0;
  _$jscoverage['promise.js'][101] = 0;
  _$jscoverage['promise.js'][102] = 0;
  _$jscoverage['promise.js'][111] = 0;
  _$jscoverage['promise.js'][112] = 0;
  _$jscoverage['promise.js'][114] = 0;
  _$jscoverage['promise.js'][115] = 0;
  _$jscoverage['promise.js'][116] = 0;
  _$jscoverage['promise.js'][125] = 0;
  _$jscoverage['promise.js'][126] = 0;
  _$jscoverage['promise.js'][128] = 0;
  _$jscoverage['promise.js'][129] = 0;
  _$jscoverage['promise.js'][130] = 0;
  _$jscoverage['promise.js'][140] = 0;
  _$jscoverage['promise.js'][141] = 0;
  _$jscoverage['promise.js'][142] = 0;
  _$jscoverage['promise.js'][151] = 0;
  _$jscoverage['promise.js'][152] = 0;
  _$jscoverage['promise.js'][153] = 0;
  _$jscoverage['promise.js'][155] = 0;
  _$jscoverage['promise.js'][156] = 0;
  _$jscoverage['promise.js'][163] = 0;
  _$jscoverage['promise.js'][211] = 0;
  _$jscoverage['promise.js'][212] = 0;
  _$jscoverage['promise.js'][213] = 0;
  _$jscoverage['promise.js'][214] = 0;
  _$jscoverage['promise.js'][215] = 0;
  _$jscoverage['promise.js'][225] = 0;
  _$jscoverage['promise.js'][226] = 0;
  _$jscoverage['promise.js'][227] = 0;
  _$jscoverage['promise.js'][228] = 0;
  _$jscoverage['promise.js'][230] = 0;
  _$jscoverage['promise.js'][231] = 0;
  _$jscoverage['promise.js'][232] = 0;
  _$jscoverage['promise.js'][233] = 0;
  _$jscoverage['promise.js'][242] = 0;
  _$jscoverage['promise.js'][243] = 0;
  _$jscoverage['promise.js'][244] = 0;
  _$jscoverage['promise.js'][247] = 0;
  _$jscoverage['promise.js'][248] = 0;
  _$jscoverage['promise.js'][254] = 0;
  _$jscoverage['promise.js'][255] = 0;
  _$jscoverage['promise.js'][256] = 0;
  _$jscoverage['promise.js'][258] = 0;
  _$jscoverage['promise.js'][261] = 0;
  _$jscoverage['promise.js'][265] = 0;
  _$jscoverage['promise.js'][266] = 0;
  _$jscoverage['promise.js'][267] = 0;
  _$jscoverage['promise.js'][269] = 0;
  _$jscoverage['promise.js'][272] = 0;
  _$jscoverage['promise.js'][277] = 0;
  _$jscoverage['promise.js'][278] = 0;
  _$jscoverage['promise.js'][280] = 0;
  _$jscoverage['promise.js'][281] = 0;
  _$jscoverage['promise.js'][282] = 0;
  _$jscoverage['promise.js'][283] = 0;
  _$jscoverage['promise.js'][285] = 0;
  _$jscoverage['promise.js'][290] = 0;
  _$jscoverage['promise.js'][291] = 0;
  _$jscoverage['promise.js'][293] = 0;
  _$jscoverage['promise.js'][294] = 0;
  _$jscoverage['promise.js'][295] = 0;
  _$jscoverage['promise.js'][296] = 0;
  _$jscoverage['promise.js'][298] = 0;
  _$jscoverage['promise.js'][303] = 0;
  _$jscoverage['promise.js'][304] = 0;
}
_$jscoverage['promise.js'][1]++;
var hitch = require("./base/functions").hitch, define = require("./define").define, base = require("./base");
_$jscoverage['promise.js'][4]++;
var Promise = define(null, {instance: {__fired: false, __results: null, __error: null, __errorCbs: null, __cbs: null, constructor: (function () {
  _$jscoverage['promise.js'][48]++;
  this.__errorCbs = [];
  _$jscoverage['promise.js'][49]++;
  this.__cbs = [];
}), __resolve: (function () {
  _$jscoverage['promise.js'][55]++;
  if (! this.__fired) {
    _$jscoverage['promise.js'][56]++;
    this.__fired = true;
    _$jscoverage['promise.js'][57]++;
    var cbs = this.__error? this.__errorCbs: this.__cbs, len = cbs.length, i, results = this.__error || this.__results;
    _$jscoverage['promise.js'][60]++;
    for (i = 0; i < len; i++) {
      _$jscoverage['promise.js'][61]++;
      cbs[i].apply(this, results);
}
  }
}), addCallback: (function (cb) {
  _$jscoverage['promise.js'][73]++;
  if (cb) {
    _$jscoverage['promise.js'][74]++;
    if (this.__fired && this.__results) {
      _$jscoverage['promise.js'][75]++;
      cb.apply(this, this.__results);
    }
    else {
      _$jscoverage['promise.js'][77]++;
      this.__cbs.push(cb);
    }
  }
  _$jscoverage['promise.js'][80]++;
  return this;
}), addErrback: (function (cb) {
  _$jscoverage['promise.js'][90]++;
  if (cb) {
    _$jscoverage['promise.js'][91]++;
    if (this.__fired && this.__error) {
      _$jscoverage['promise.js'][92]++;
      cb.apply(this, this.__error);
    }
    else {
      _$jscoverage['promise.js'][94]++;
      this.__errorCbs.push(cb);
    }
  }
}), both: (function (cb) {
  _$jscoverage['promise.js'][100]++;
  this.addCallback(cb);
  _$jscoverage['promise.js'][101]++;
  this.addErrback(cb);
  _$jscoverage['promise.js'][102]++;
  return this;
}), callback: (function () {
  _$jscoverage['promise.js'][111]++;
  if (this.__fired) {
    _$jscoverage['promise.js'][112]++;
    throw new Error("Already fired!");
  }
  _$jscoverage['promise.js'][114]++;
  this.__results = Array.prototype.slice.call(arguments);
  _$jscoverage['promise.js'][115]++;
  this.__resolve();
  _$jscoverage['promise.js'][116]++;
  return this;
}), errback: (function (i) {
  _$jscoverage['promise.js'][125]++;
  if (this.__fired) {
    _$jscoverage['promise.js'][126]++;
    throw new Error("Already fired!");
  }
  _$jscoverage['promise.js'][128]++;
  this.__error = Array.prototype.slice.call(arguments);
  _$jscoverage['promise.js'][129]++;
  this.__resolve();
  _$jscoverage['promise.js'][130]++;
  return this;
}), then: (function (callback, errback) {
  _$jscoverage['promise.js'][140]++;
  this.addCallback(callback);
  _$jscoverage['promise.js'][141]++;
  this.addErrback(errback);
  _$jscoverage['promise.js'][142]++;
  return this;
}), chain: (function (callback, errback) {
  _$jscoverage['promise.js'][151]++;
  var promise = new Promise();
  _$jscoverage['promise.js'][152]++;
  this.addCallback((function (results) {
  _$jscoverage['promise.js'][153]++;
  callback.call(this, results).then(hitch(promise, "callback"), hitch(promise, "errback"));
}));
  _$jscoverage['promise.js'][155]++;
  this.addErrback(errback);
  _$jscoverage['promise.js'][156]++;
  return promise;
})}});
_$jscoverage['promise.js'][163]++;
var PromiseList = define(Promise, {instance: {__results: null, __errors: null, __promiseLength: 0, __defLength: 0, __firedLength: 0, constructor: (function (defs) {
  _$jscoverage['promise.js'][211]++;
  this.__defLength = defs.length;
  _$jscoverage['promise.js'][212]++;
  this.__errors = [];
  _$jscoverage['promise.js'][213]++;
  this.__results = [];
  _$jscoverage['promise.js'][214]++;
  this["super"](arguments);
  _$jscoverage['promise.js'][215]++;
  defs.forEach(this.__addPromise, this);
}), __addPromise: (function (promise, i) {
  _$jscoverage['promise.js'][225]++;
  promise.addCallback(hitch(this, (function () {
  _$jscoverage['promise.js'][226]++;
  var args = Array.prototype.slice.call(arguments);
  _$jscoverage['promise.js'][227]++;
  args.unshift(i);
  _$jscoverage['promise.js'][228]++;
  this.callback.apply(this, args);
})));
  _$jscoverage['promise.js'][230]++;
  promise.addErrback(hitch(this, (function () {
  _$jscoverage['promise.js'][231]++;
  var args = Array.prototype.slice.call(arguments);
  _$jscoverage['promise.js'][232]++;
  args.unshift(i);
  _$jscoverage['promise.js'][233]++;
  this.errback.apply(this, args);
})));
}), __resolve: (function () {
  _$jscoverage['promise.js'][242]++;
  if (! this.__fired) {
    _$jscoverage['promise.js'][243]++;
    this.__fired = true;
    _$jscoverage['promise.js'][244]++;
    var cbs = this.__errors.length? this.__errorCbs: this.__cbs, len = cbs.length, i, results = this.__errors.length? this.__errors: this.__results;
    _$jscoverage['promise.js'][247]++;
    for (i = 0; i < len; i++) {
      _$jscoverage['promise.js'][248]++;
      cbs[i].call(this, results);
}
  }
}), addCallback: (function (cb) {
  _$jscoverage['promise.js'][254]++;
  if (cb) {
    _$jscoverage['promise.js'][255]++;
    if (this.__fired && ! this.__errors.length) {
      _$jscoverage['promise.js'][256]++;
      cb.call(this, this.__results);
    }
    else {
      _$jscoverage['promise.js'][258]++;
      this.__cbs.push(cb);
    }
  }
  _$jscoverage['promise.js'][261]++;
  return this;
}), addErrback: (function (cb) {
  _$jscoverage['promise.js'][265]++;
  if (cb) {
    _$jscoverage['promise.js'][266]++;
    if (this.__fired && this.__errors.length) {
      _$jscoverage['promise.js'][267]++;
      cb.call(this, this.__errors);
    }
    else {
      _$jscoverage['promise.js'][269]++;
      this.__errorCbs.push(cb);
    }
  }
  _$jscoverage['promise.js'][272]++;
  return this;
}), callback: (function (i) {
  _$jscoverage['promise.js'][277]++;
  if (this.__fired) {
    _$jscoverage['promise.js'][278]++;
    throw new Error("Already fired!");
  }
  _$jscoverage['promise.js'][280]++;
  this.__results[i] = Array.prototype.slice.call(arguments);
  _$jscoverage['promise.js'][281]++;
  this.__firedLength++;
  _$jscoverage['promise.js'][282]++;
  if (this.__firedLength == this.__defLength) {
    _$jscoverage['promise.js'][283]++;
    this.__resolve();
  }
  _$jscoverage['promise.js'][285]++;
  return this;
}), errback: (function (i) {
  _$jscoverage['promise.js'][290]++;
  if (this.__fired) {
    _$jscoverage['promise.js'][291]++;
    throw new Error("Already fired!");
  }
  _$jscoverage['promise.js'][293]++;
  this.__errors[i] = Array.prototype.slice.call(arguments);
  _$jscoverage['promise.js'][294]++;
  this.__firedLength++;
  _$jscoverage['promise.js'][295]++;
  if (this.__firedLength == this.__defLength) {
    _$jscoverage['promise.js'][296]++;
    this.__resolve();
  }
  _$jscoverage['promise.js'][298]++;
  return this;
})}});
_$jscoverage['promise.js'][303]++;
exports.Promise = Promise;
_$jscoverage['promise.js'][304]++;
exports.PromiseList = PromiseList;
_$jscoverage['promise.js'].source = ["var hitch = require(\"./base/functions\").hitch,","    define = require(\"./define\").define, base = require(\"./base\");","","var Promise = define(null, {","    instance : {","        /** @lends comb.Promise.prototype */","        __fired : false,","","        __results : null,","","        __error : null,","","        __errorCbs : null,","","        __cbs : null,","","        /**","         * Promise object used for handling a thread","         *@example","         *          var myFunc = function(){","         *              var promise = new Promise();","         *              //callback the promise after 10 Secs","         *              setTimeout(hitch(promise, \"callback\"), 10000);","         *              return promise;","         *          }","         *          var myFunc2 = function(){","         *              var promises =[];","         *              for(var i = 0; i &lt; 10; i++){","         *                  promises.push(myFunc);","         *              }","         *              //create a new promise list with all 10 promises","         *              return new PromiseList(promises);","         *          }","         *","         *          myFunc.then(do something...)","         *          myFunc.addCallback(do something...)","         *          myFunc.cain(myfunc).then(do something...)","         *          myFunc.cain(myfunc).addCallback(do something...)","         *","         *          myFunc2.then(do something...)","         *          myFunc2.addCallback(do something...)","         *          myFunc2.cain(myfunc).then(do something...)","         *          myFunc2.cain(myfunc).addCallback(do something...)","         *  @memberOf comb","         * @constructs","         */","        constructor : function() {","            this.__errorCbs = [];","            this.__cbs = [];","        },","        /**","         * @private","         */","        __resolve : function() {","            if (!this.__fired) {","                this.__fired = true;","                var cbs = this.__error ? this.__errorCbs : this.__cbs,","                    len = cbs.length, i,","                    results = this.__error || this.__results;","                for (i = 0; i &lt; len; i++) {","                    cbs[i].apply(this, results);","                }","            }","        },","","        /**","         * Add a callback to the callback chain of the promise","         *","         *","         * @param {Function} cb the function to callback when the promise is resolved","         */","        addCallback : function(cb) {","            if (cb) {","                if (this.__fired &amp;&amp; this.__results) {","                    cb.apply(this, this.__results);","                } else {","                    this.__cbs.push(cb);","                }","            }","            return this;","        },","","","        /**","         * Add a callback to the errback chain of the promise","         *","         * @param {Function} cb the function to callback when the promise errors","         */","        addErrback : function(cb) {","            if (cb) {","                if (this.__fired &amp;&amp; this.__error) {","                    cb.apply(this, this.__error);","                } else {","                    this.__errorCbs.push(cb);","                }","            }","        },","","        both : function(cb) {","            this.addCallback(cb);","            this.addErrback(cb);","            return this;","        },","","        /**","         * When called all functions registered as callbacks are called with the passed in results.","         *","         * @param anything variable number of results to pass back to listeners of the promise","         */","        callback : function() {","            if (this.__fired) {","                throw new Error(\"Already fired!\");","            }","            this.__results = Array.prototype.slice.call(arguments);","            this.__resolve();","            return this;","        },","","        /**","         * When called all functions registered as errbacks are called with the passed in error(s)","         *","         * @param anything variable number of errors to pass back to listeners of the promise","         */","        errback : function(i) {","            if (this.__fired) {","                throw new Error(\"Already fired!\");","            }","            this.__error = Array.prototype.slice.call(arguments);","            this.__resolve();","            return this;","        },","","        /**","         * Call to specify action to take after promise completes or errors","         *","         * @param {Function} [callback=null] function to call after the promise completes successfully","         * @param {Function} [errback=null] function to call if the promise errors","         */","        then : function(callback, errback) {","            this.addCallback(callback);","            this.addErrback(errback);","            return this;","        },","","        /**","         * Call to chaining of promises","         * @param callback method to call that returns a promise to call after this one completes.","         * @param errback method to call if this promise errors.","         */","        chain : function(callback, errback) {","            var promise = new Promise();","            this.addCallback(function(results) {","                callback.call(this, results).then(hitch(promise, \"callback\"), hitch(promise, \"errback\"));","            });","            this.addErrback(errback);","            return promise;","        }","","    }","});","","","var PromiseList = define(Promise, {","    instance : {","        /** @lends comb.PromiseList.prototype */","","        /*@private*/","        __results : null,","","        /*@private*/","        __errors : null,","","        /*@private*/","        __promiseLength : 0,","","        /*@private*/","        __defLength : 0,","","        /*@private*/","        __firedLength : 0,","","        /**","         *","         *  PromiseList object used for handling a list of Promises","         * @example         var myFunc = function(){","         *              var promise = new Promise();","         *              //callback the promise after 10 Secs","         *              setTimeout(hitch(promise, \"callback\"), 10000);","         *              return promise;","         *          }","         *          var myFunc2 = function(){","         *              var promises =[];","         *              for(var i = 0; i &lt; 10; i++){","         *                  promises.push(myFunc);","         *              }","         *              //create a new promise list with all 10 promises","         *              return new PromiseList(promises);","         *          }","         *          var pl = new comb.PomiseList([myFunc(), myFunc2()]);","         *          pl.then(do something...)","         *          pl.addCallback(do something...)","         *          pl.cain(myfunc).then(do something...)","         *          pl.cain(myfunc).addCallback(do something...)","         *","         *  @param {comb.Promise[]} [defs=[]] the list of promises","         * @constructs","         * @augments comb.Promise","         * @memberOf comb","         * */","        constructor : function(defs) {","            this.__defLength = defs.length;","            this.__errors = [];","            this.__results = [];","            this.super(arguments);","            defs.forEach(this.__addPromise, this);","        },","","        /**","         * Add a promise to our chain","         * @private","         * @param promise the promise to add to our chain","         * @param i the index of the promise in our chain","         */","        __addPromise : function(promise, i) {","            promise.addCallback(hitch(this, function() {","                var args = Array.prototype.slice.call(arguments);","                args.unshift(i);","                this.callback.apply(this, args);","            }));","            promise.addErrback(hitch(this, function() {","                var args = Array.prototype.slice.call(arguments);","                args.unshift(i);","                this.errback.apply(this, args);","            }));","        },","","        /**","         * Resolves the promise","         * @private","         */","        __resolve : function() {","            if (!this.__fired) {","                this.__fired = true;","                var cbs = this.__errors.length ? this.__errorCbs : this.__cbs,","                    len = cbs.length, i,","                    results = this.__errors.length ? this.__errors : this.__results;","                for (i = 0; i &lt; len; i++) {","                    cbs[i].call(this, results);","                }","            }","        },","","        addCallback : function(cb) {","            if (cb) {","                if (this.__fired &amp;&amp; !this.__errors.length) {","                    cb.call(this, this.__results);","                } else {","                    this.__cbs.push(cb);","                }","            }","            return this;","        },","","        addErrback : function(cb) {","            if (cb) {","                if (this.__fired &amp;&amp; this.__errors.length) {","                    cb.call(this, this.__errors);","                } else {","                    this.__errorCbs.push(cb);","                }","            }","            return this;","        },","","","        callback : function(i) {","            if (this.__fired) {","                throw new Error(\"Already fired!\");","            }","            this.__results[i] = (Array.prototype.slice.call(arguments));","            this.__firedLength++;","            if (this.__firedLength == this.__defLength) {","                this.__resolve();","            }","            return this;","        },","","","        errback : function(i) {","            if (this.__fired) {","                throw new Error(\"Already fired!\");","            }","            this.__errors[i] = Array.prototype.slice.call(arguments);","            this.__firedLength++;","            if (this.__firedLength == this.__defLength) {","                this.__resolve();","            }","            return this;","        }","","    }","});","exports.Promise = Promise;","exports.PromiseList = PromiseList;"];
