// Two serial queues, one per compute resource, shared by every user of the platform. // // The whisper.cpp server and the torch worker each run one job at a time — both saturate their // device, so concurrency inside them buys nothing. What the platform owes its users is fairness // and calm under simultaneous requests: jobs enter here and run strictly in arrival order, and a // slow episode ahead of you delays you but never breaks you. // // The two queues are deliberately independent: a probe or diarization runs on the torch worker // WHILE someone else's transcription runs on Whisper. That is what makes the conversation check // free for solo memos — it happens on the other resource's time. // // v2 (planned, not built): feature-aware ordering — short memos ahead of hour-long episodes, // probes ahead of full diarizations. The queue object is the seam where that goes; callers will // not change. export class SerialQueue { private tail: Promise = Promise.resolve(); private depth = 0; /** Jobs currently running or waiting. */ get pending(): number { return this.depth; } run(job: () => Promise): Promise { this.depth += 1; const result = this.tail.then(job).finally(() => { this.depth -= 1; }); // The chain itself must survive a failed job — the failure belongs to the caller who // submitted it, not to everyone queued behind them. this.tail = result.catch(() => undefined); return result; } } export const whisperQueue = new SerialQueue(); export const workerQueue = new SerialQueue();