| 141 | } |
| 142 | |
| 143 | private async runNext() { |
| 144 | const next = this.queue.shift(); |
| 145 | if (next) { |
| 146 | this.running.push(next.type || "anonymous"); |
| 147 | this.logState(); |
| 148 | |
| 149 | try { |
| 150 | await next(); |
| 151 | } catch (e: any) { |
| 152 | this.logger.log("DEBUG", e); |
| 153 | } finally { |
| 154 | const index = this.running.indexOf(next.type || "anonymous"); |
| 155 | if (index !== -1) { |
| 156 | this.running.splice(index, 1); |
| 157 | } |
| 158 | this.notifyWorkFinish(); |
| 159 | this.logState(); |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | private logState() { |
| 165 | this.logger.logLabeled("DEBUG", "work-queue", JSON.stringify(this.getState())); |