Drain a cooperative work queue one item at a time and label the throughput from a deterministic count.

queue drain A queue report removes each item in order and keeps the drained count scalar, so the drain order never varies.

Async Queue Coordination Report

pending
async_queue.lua
Replay: real traced execution (multi-file project)
local pending = 4
local remaining = pending
local drained = 0

while remaining > 0 do
  remaining = remaining - 1
  drained = drained + 1
end

local report_status = "empty"
if drained >= 7 then
  report_status = "backlog"
elseif drained > 0 then
  report_status = "flowing"
end

print("pending=" .. pending .. " drained=" .. drained .. " status=" .. report_status)
local pending = 0
local remaining = pending
local drained = 0

while remaining > 0 do
  remaining = remaining - 1
  drained = drained + 1
end

local report_status = "empty"
if drained >= 7 then
  report_status = "backlog"
elseif drained > 0 then
  report_status = "flowing"
end

print("pending=" .. pending .. " drained=" .. drained .. " status=" .. report_status)
local pending = 7
local remaining = pending
local drained = 0

while remaining > 0 do
  remaining = remaining - 1
  drained = drained + 1
end

local report_status = "empty"
if drained >= 7 then
  report_status = "backlog"
elseif drained > 0 then
  report_status = "flowing"
end

print("pending=" .. pending .. " drained=" .. drained .. " status=" .. report_status)
  1. pending ← 4, remaining ← 4, drained ← 0

    1local pending→ 4 = 4 --@pending=0, 72local remaining→ 4 = pending43local drained→ 0 = 0
  2. remaining ← 3, drained ← 1

    pass 1 of 4
    5while remaining4 > 0 do6  remaining→ 3 = remaining - 17  drained→ 1 = drained + 18end
    All 4 passes — pass 1 is the card above
    passremainingdrained
    14 30 1
    23 21 2
    32 12 3
    41 03 4
  3. report_status ← empty

    10local report_status→ empty = "empty"11if drained >= 7 then
  4. report_status ← flowing

    12  report_status = "backlog"13elseif drained4 > 0 then14  report_status→ flowing = "flowing"15end
  5. print("pending=" .. pending .. " drained=" .. drained .. " status=" ..…

    17print("pending=" .. pending4 .. " drained=" .. drained4 .. " status=" .. report_statusflowing)
    outputpending=4 drained=4 status=flowing
  1. pending ← 0, remaining ← 0, drained ← 0, report_status ← empty

    1local pending→ 0 = 02local remaining→ 0 = pending03local drained→ 0 = 045while remaining > 0 do6  remaining = remaining - 17  drained = drained + 18end910local report_status→ empty = "empty"11if drained >= 7 then12  report_status = "backlog"13elseif drained > 0 then14  report_status = "flowing"15end1617print("pending=" .. pending0 .. " drained=" .. drained0 .. " status=" .. report_statusempty)
    outputpending=0 drained=0 status=empty
  1. pending ← 7, remaining ← 7, drained ← 0

    1local pending→ 7 = 72local remaining→ 7 = pending73local drained→ 0 = 0
  2. remaining ← 6, drained ← 1

    pass 1 of 7
    5while remaining7 > 0 do6  remaining→ 6 = remaining - 17  drained→ 1 = drained + 18end
    All 7 passes — pass 1 is the card above
    passremainingdrained
    17 60 1
    26 51 2
    35 42 3
    44 33 4
    53 24 5
    62 15 6
    71 06 7
  3. report_status ← empty

    10local report_status→ empty = "empty"11if drained >= 7 then
  4. report_status ← backlog

    10local report_status = "empty"11if drained7 >= 7 then12  report_status→ backlog = "backlog"13elseif drained > 0 then
  5. print("pending=" .. pending .. " drained=" .. drained .. " status=" ..…

    17print("pending=" .. pending7 .. " drained=" .. drained7 .. " status=" .. report_statusbacklog)
    outputpending=7 drained=7 status=backlog