emitter

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: MIT Imports: 3 Imported by: 4 modules, 8 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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