leadership

package
v0.1.0-alpha.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 27, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

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

type StateReplayer[T busevents.Event] struct {
	// contains filtered or unexported fields
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL