Concurrency Coordination Reports
Async Queue Coordination Report
Drain an awaited work queue one item at a time and label the throughput from a deterministic count.
Async Queue Coordination Report
async_queue_coordination.js
const pending = 4;
let drained = 0;
let outcome = "empty";
async function coordinate(count) {
const queue = Array.from({ length: count }, (_, i) => i + 1);
while (queue.length > 0) {
const item = queue.shift();
await Promise.resolve(item);
drained += 1;
}
if (drained >= 7) {
outcome = "backlog";
} else if (drained > 0) {
outcome = "flowing";
}
console.log(`pending=${count} drained=${drained} status=${outcome}`);
}
coordinate(pending);
queue drain
An async queue report awaits each item in turn and keeps the drained count scalar, so the drain order never varies.