v1.1.3

Queue Lifecycle

Last updated


This page explains the three queue states, which calls each state allows, and how Shutdown drains the heap within a deadline.

Queue State


State is an atomic.Uint32, and every transition goes through CompareAndSwap.
StateEntered ByEnqueueStartShutdown
CreatedNewAllowed (tasks wait)Moves to RunningMoves to Closed
RunningStartAllowedqueue already startedMoves to Closed
ClosedShutdownstaging queue is closedqueue already closedReturns nil

Shutdown


In the Closed state Shutdown lets workers keep popping until the heap is empty, then cancels the root ctx. If the Shutdown ctx expires first, it cancels the root ctx immediately and returns shutdown timeout: N tasks remaining.
SituationResult
Heap drains before the deadlineEvery queued task runs; returns nil
Deadline expires firstRunning and still-queued tasks get a cancelled ctx; returns shutdown timeout: N tasks remaining
Called againReturns nil immediately
Called before StartMoves to Closed and returns nil; queued tasks never run
中文