diff --git a/src/queue.js b/src/queue.js index 3b6e3ad..7749ea7 100644 --- a/src/queue.js +++ b/src/queue.js @@ -1,7 +1,10 @@ +import { WorkerPool } from "./worker-pool.js"; + // A tiny in-memory job queue. Jobs run one at a time, in order. export class Queue { #jobs = []; #running = false; + #pool = new WorkerPool({ size: 4 }); push(job) { this.#jobs.push(job); @@ -19,7 +22,7 @@ export class Queue { while (this.#jobs.length) { const job = this.#jobs.shift(); try { - await job(); + await this.#pool.run(job); } catch { // A failing job must not wedge the queue or let the next job start early. }