* Begin processing work from the queue.
()
| 63 | * Begin processing work from the queue. |
| 64 | */ |
| 65 | async start() { |
| 66 | if (!this.stopped) { |
| 67 | return; |
| 68 | } |
| 69 | |
| 70 | this.stopped = false; |
| 71 | while (!this.stopped) { |
| 72 | // If the queue is empty, wait until something is added. |
| 73 | if (!this.queue.length) { |
| 74 | await new Promise<void>((res) => { |
| 75 | this.notifyQueue = res; |
| 76 | }); |
| 77 | } |
| 78 | |
| 79 | // If we have too many jobs out, wait until something finishes. |
| 80 | if (this.running.length >= this.maxParallelWork) { |
| 81 | this.logger.logLabeled( |
| 82 | "DEBUG", |
| 83 | "work-queue", |
| 84 | `waiting for work to finish (running=${this.running})`, |
| 85 | ); |
| 86 | await new Promise<void>((res) => { |
| 87 | this.notifyWorkFinish = res; |
| 88 | }); |
| 89 | } |
| 90 | |
| 91 | const workPromise = this.runNext(); |
| 92 | if (this.mode === FunctionsExecutionMode.SEQUENTIAL) { |
| 93 | await workPromise; |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Stop processing work from the queue. |
nothing calls this directly
no test coverage detected