* Run one item * @return {Promise}
()
| 67 | * @return {Promise} |
| 68 | */ |
| 69 | dequeue() { |
| 70 | var inwait, task, result |
| 71 | |
| 72 | if (this._q.length && !this.paused) { |
| 73 | inwait = this._q.shift() |
| 74 | task = inwait.task |
| 75 | if (task) { |
| 76 | // console.log(task) |
| 77 | |
| 78 | result = task.apply(this.context, inwait.args) |
| 79 | |
| 80 | if (result && typeof result['then'] === 'function') { |
| 81 | // Task is a function that returns a promise |
| 82 | return result.then( |
| 83 | function () { |
| 84 | inwait.deferred.resolve.apply(this.context, arguments) |
| 85 | }.bind(this), |
| 86 | function () { |
| 87 | inwait.deferred.reject.apply(this.context, arguments) |
| 88 | }.bind(this), |
| 89 | ) |
| 90 | } else { |
| 91 | // Task resolves immediately |
| 92 | inwait.deferred.resolve.apply(this.context, result) |
| 93 | return inwait.promise |
| 94 | } |
| 95 | } else if (inwait.promise) { |
| 96 | // Task is a promise |
| 97 | return inwait.promise |
| 98 | } |
| 99 | } else { |
| 100 | inwait = new defer() |
| 101 | inwait.deferred.resolve() |
| 102 | return inwait.promise |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | // Run All Immediately |
| 107 | dump() { |