Update docs on shutdown and draining

Kubernetes-commit: 67aaa956da3e6110e8155cc08539c488fc5e1298
This commit is contained in:
Nelo-T. Wallus 2025-07-09 21:43:30 +02:00 committed by Kubernetes Publisher
parent f84a70ae3c
commit 6116f46372

View File

@ -212,7 +212,9 @@ type Typed[t comparable] struct {
clock clock.WithTicker clock clock.WithTicker
} }
// Add marks item as needing processing. // Add marks item as needing processing. When the queue is shutdown new
// items will silently be ignored and not queued or marked as dirty for
// reprocessing.
func (q *Typed[T]) Add(item T) { func (q *Typed[T]) Add(item T) {
q.cond.L.Lock() q.cond.L.Lock()
defer q.cond.L.Unlock() defer q.cond.L.Unlock()
@ -290,8 +292,9 @@ func (q *Typed[T]) Done(item T) {
} }
} }
// ShutDown will cause q to ignore all new items added to it and // ShutDown will cause q to ignore all new items added to it. Worker
// immediately instruct the worker goroutines to exit. // goroutines will continue processing items in the queue until it is
// empty and then receive the shutdown signal.
func (q *Typed[T]) ShutDown() { func (q *Typed[T]) ShutDown() {
q.cond.L.Lock() q.cond.L.Lock()
defer q.cond.L.Unlock() defer q.cond.L.Unlock()
@ -301,15 +304,12 @@ func (q *Typed[T]) ShutDown() {
q.cond.Broadcast() q.cond.Broadcast()
} }
// ShutDownWithDrain will cause q to ignore all new items added to it. As soon // ShutDownWithDrain is equivalent to ShutDown but waits until all items
// as the worker goroutines have "drained", i.e: finished processing and called // in the queue have been processed.
// Done on all existing items in the queue; they will be instructed to exit and // ShutDown can be called after ShutDownWithDrain to force
// ShutDownWithDrain will return. Hence: a strict requirement for using this is; // ShutDownWithDrain to stop waiting.
// your workers must ensure that Done is called on all items in the queue once // Workers must call Done on an item after processing it, otherwise
// the shut down has been initiated, if that is not the case: this will block // ShutDownWithDrain will block indefinitely.
// indefinitely. It is, however, safe to call ShutDown after having called
// ShutDownWithDrain, as to force the queue shut down to terminate immediately
// without waiting for the drainage.
func (q *Typed[T]) ShutDownWithDrain() { func (q *Typed[T]) ShutDownWithDrain() {
q.cond.L.Lock() q.cond.L.Lock()
defer q.cond.L.Unlock() defer q.cond.L.Unlock()