Documentation
¶
Overview ¶
Package leadership provides utilities for handling leadership transitions in event-driven components.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type StateReplayer ¶
StateReplayer caches the latest event of type T and re-publishes it on demand (typically in response to BecameLeaderEvent).
This solves the "late subscriber problem" where leader-only components start subscribing AFTER all-replica components have already published critical state events. By caching and replaying the last state, new leaders receive the current state immediately.
Thread-safe for concurrent access.
func NewStateReplayer ¶
func NewStateReplayer[T busevents.Event](eventBus *busevents.EventBus) *StateReplayer[T]
NewStateReplayer creates a new StateReplayer that publishes replay events to the given EventBus.
func (*StateReplayer[T]) Cache ¶
func (r *StateReplayer[T]) Cache(event T)
Cache stores the event for later replay. Only the latest event is retained (previous events are overwritten).
func (*StateReplayer[T]) Get ¶
func (r *StateReplayer[T]) Get() (T, bool)
Get returns the cached event and whether it exists.
func (*StateReplayer[T]) HasState ¶
func (r *StateReplayer[T]) HasState() bool
HasState returns whether an event has been cached.
func (*StateReplayer[T]) Replay ¶
func (r *StateReplayer[T]) Replay() bool
Replay re-publishes the cached event to the EventBus. Returns true if an event was replayed, false if no state was cached.