Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/queue.js
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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.
}
Expand Down
Loading