Code coverage report for lib/taskqueue.js

Statements: 100% (23 / 23)      Branches: 100% (4 / 4)      Functions: 100% (5 / 5)      Lines: 100% (23 / 23)      Ignored: none     

All files » lib/ » taskqueue.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    1   1 6365 6365 6365     1 6371 6371 28 17     6343 6247         1 22 22     1 6343 6343 6343     1 6264 6264 6      
'use strict';
 
module.exports = 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();
  }
};