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

Async Queue Coordination Report

async_queue.lua
local pending = 
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 = 
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 = 
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)
queue drain A queue report removes each item in order and keeps the drained count scalar, so the drain order never varies.