all files / lib/ taskqueue.js

100% Statements 25/25
100% Branches 4/4
100% Functions 5/5
100% Lines 25/25
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          6853× 6853× 6853×     6857× 6857× 13×     6844× 6558×             6844× 6844× 6844×     6562× 6562×    
"use strict";
 
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = TaskQueue;
 
function TaskQueue() {
  this.isReady = false;
  this.failed = false;
  this.queue = [];
}
 
TaskQueue.prototype.execute = function () {
  var fun;
  if (this.failed) {
    while (fun = this.queue.shift()) {
      fun(this.failed);
    }
  } else {
    while (fun = this.queue.shift()) {
      fun();
    }
  }
};
 
TaskQueue.prototype.fail = function (err) {
  this.failed = err;
  this.execute();
};
 
TaskQueue.prototype.ready = function (db) {
  this.isReady = true;
  this.db = db;
  this.execute();
};
 
TaskQueue.prototype.addTask = function (fun) {
  this.queue.push(fun);
  if (this.failed) {
    this.execute();
  }
};
module.exports = exports['default'];