Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Subscribe ¶ added in v0.5.1
func Subscribe[T Event](subscriber Subscriber, eventName EventName, handler TypedEventHandler[T]) error
Subscribe subscribes to an event of a given type. It allows to use a typed handler.
Types ¶
type Callback ¶
Callback is a callback function that is called when an event is processed by the listener.
type EventBus ¶
type EventBus interface { Start() error Stop() error Publisher Subscriber }
EventBus allows to publish and subscribe to events. It is a simple interface that allows to decouple the event publishing from the event handling. The handler can return an error, which will be returned by the Publish method. The publisher can publish as fire-and-forget, or wait for the handler to confirm the processing (replyHandler).
type EventEnvelope ¶
type EventEnvelope struct { Event Event Err error Ctx context.Context Callback Callback ShouldWait bool }
EventEnvelope is a wrapper around the event that is sent to the bus. It holds other information that is used by the bus to process the event.
func (*EventEnvelope) ProcessOptions ¶
func (e *EventEnvelope) ProcessOptions(options []Option)
ProcessOptions processes the options and sets the values on the envelope.
type Option ¶
type Option func(*EventEnvelope)
func WithContext ¶ added in v0.5.1
type Subscriber ¶ added in v0.5.1
type Subscriber interface { // Subscribe subscribes to an event. // The handler will be called when the event is published. // The handler can return an error, which will be returned by the Publish method. Subscribe(eventName EventName, handler EventHandler) error }