emitter

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 3 Imported by: 0

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

func NewEmitter[T any]() Emitter[T]

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

type Subscriber[T any] func(ctx context.Context, value T)

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.

Jump to

Keyboard shortcuts

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