Documentation
¶
Overview ¶
Package coalesce provides utilities for event coalescing in controller components.
Event coalescing implements the "latest wins" pattern where intermediate events are skipped when newer events of the same type are available. This prevents queue backlog when events arrive faster than they can be processed.
Only events that implement CoalescibleEvent and return Coalescible() == true are coalesced. Other events are passed to the handleOther callback.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DrainLatest ¶
func DrainLatest[T busevents.Event]( eventChan <-chan busevents.Event, handleOther func(busevents.Event), ) (latest T, supersededCount int)
DrainLatest drains the event channel and returns the latest coalescible event of type T. Non-coalescible events and events of other types are passed to handleOther. Returns the zero value of T and 0 if no coalescible events were found.
An event is coalescible if:
- It matches type T
- It implements CoalescibleEvent interface
- Its Coalescible() method returns true
Usage pattern:
func (c *Component) handleSomeEvent(event *events.SomeEvent) {
c.performWork(event)
// After work completes, drain for latest coalescible event
for {
latest, superseded := coalesce.DrainLatest[*events.SomeEvent](
c.eventChan,
c.handleEvent, // Handle non-coalescible and other event types
)
if latest == nil {
return
}
c.logger.Debug("Processing coalesced event",
"superseded_count", superseded)
c.performWork(latest)
}
}
Types ¶
This section is empty.