Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Emitter ¶
type Emitter[T any] interface { // Emit sends a value to all active subscribers. // Each subscriber runs in its own goroutine with a derived context from closer. Emit(ctx context.Context, value T) // Subscribe adds a new subscriber to the emitter. // Returns an UnsubscribeFunc that can be used to remove the subscriber. Subscribe(subscriber Subscriber[T]) UnsubscribeFunc Wait() }
Emitter defines an interface for event-driven communication. It allows subscribing to events and emitting values to all subscribers.
func NewEmitter ¶
NewEmitter creates a new Emitter instance. The closer is used to derive contexts for subscriber goroutines, enabling graceful shutdown of all event handlers.
type Subscriber ¶
Subscriber represents a function that handles emitted events. It receives a context for cancellation and the event value.
type UnsubscribeFunc ¶
type UnsubscribeFunc func()
UnsubscribeFunc is a function returned by Subscribe() to remove a subscriber. Calling it unsubscribes the handler from future events.
Click to show internal directories.
Click to hide internal directories.