Documentation
¶
Overview ¶
Package events provides an in-process publish/subscribe event bus that implements the eventBus interface defined in the aitm package.
Index ¶
Constants ¶
const DefaultBufferSize = 64
DefaultBufferSize is the channel buffer size used when none is specified.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bus ¶
type Bus struct {
// contains filtered or unexported fields
}
Bus is a goroutine-safe publish/subscribe bus backed by in-process Go channels.
Delivery guarantee: best-effort, in-process only. Events are never persisted. If a subscriber's channel is full when Publish is called, the event is dropped for that subscriber and a warning is logged. The publisher is never blocked.
func (*Bus) Publish ¶
Publish sends e to all subscribers registered for e.Type. e.OccurredAt is set to time.Now() before delivery regardless of what the caller provides. If a subscriber's channel is full the event is dropped for that subscriber and a warning is written to the default slog logger.
The read lock is held across the send loop to prevent Unsubscribe from closing a subscriber's channel between iteration and send (which would panic). Sends are non-blocking (select + default), so the critical section stays short: concurrent publishers still run in parallel, and an Unsubscribe call only waits for in-flight publishes to return.