| export 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(); |
| } |
| }; |