Documentation
¶
Index ¶
Constants ¶
const ( DefaultExpiration = 5 * time.Second EvictionInterval = 1 * time.Second )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CooldownQueue ¶
type CooldownQueue[T any] struct { // contains filtered or unexported fields }
CooldownQueue is a queue that lets clients put events into it with a cooldown
When a client puts an event into a queue, it waits for a cooldown period before the event is forwarded to the consumer. If an event for the same key is put into the queue again before the cooldown period is over, the event is overridden and the cooldown period is reset.
Concurrency design: the TTL-cache evicter goroutine (istio.io/pkg/cache) cannot be stopped synchronously, so we must never close the channel it sends to. Instead a relay goroutine owns the consumer-facing channel (resultChan) and closes it only after the done signal is received. The intermediate (innerChan) is never closed, eliminating any "send on closed channel" panic during shutdown.
func NewCooldownQueue ¶
func NewCooldownQueue[T any](cooldown time.Duration, evictionInterval time.Duration) *CooldownQueue[T]
NewCooldownQueue returns a new Cooldown Queue
func (*CooldownQueue[T]) Closed ¶
func (q *CooldownQueue[T]) Closed() bool
func (*CooldownQueue[T]) Enqueue ¶
func (q *CooldownQueue[T]) Enqueue(e T, key string)
Enqueue enqueues an event in the Cooldown Queue
func (*CooldownQueue[T]) ResultChan ¶
func (q *CooldownQueue[T]) ResultChan() <-chan T
ResultChan returns a read-only channel for consuming events.
func (*CooldownQueue[T]) Stop ¶
func (q *CooldownQueue[T]) Stop()
Stop signals the queue to shut down. The relay goroutine closes the result channel after observing done; pending evictions not yet forwarded by then may be dropped, unblocking any for-range consumer.