Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseEvent ¶
type BaseEvent struct {
// contains filtered or unexported fields
}
The base event implements the Event interface adding some basic fields
func NewBaseEvent ¶
func (*BaseEvent) WithPayload ¶
type ErrorHandler ¶
type Event ¶
type Event interface { // Tag returns the event name Tag() string // CreatedAt returns the event creation time CreatedAt() time.Time // Payload returns the event payload Payload() any // WithCtx sets context for event. // This method will be used by the // events service when you emit an event. // This means that if you put a context this will be overrited. WithCtx(context.Context) Event // Ctx returns event context Ctx() context.Context }
Event is the main interface where the library turns around the service expects an Event interface and you can implement your own events
type EventListener ¶
type EventService ¶
type EventService struct {
// contains filtered or unexported fields
}
func NewEventService ¶
func NewEventService(config ...EventServiceConfig) *EventService
Returns a new event service with default config or custom one
func (*EventService) Emit ¶
func (e *EventService) Emit(event Event)
Emit will add a provided event to the event queue and all listeners that match with event name will react to this event
func (*EventService) IsClosed ¶
func (e *EventService) IsClosed() bool
IsClosed cheks if event service is cosed
func (*EventService) Listen ¶
func (e *EventService) Listen(tag string, listener EventListener) ListenerDestroyer
Register a new event listener and returns the destroyer for that listener. Remember tag accepts glob regex. Ej.
- listen all events: "*"
- listen all events under a namespace: "users.*"
- listen all created events: "*.created"
For more information see https://github.com/gobwas/glob
func (*EventService) Start ¶
func (e *EventService) Start()
Start turn up the event listener engine. At this moment listeners will start reacting to the emitted events
func (*EventService) Stop ¶
func (e *EventService) Stop()
Stop ends event emitting and listening. At this moment every emit or listen will panic
type EventServiceConfig ¶
type EventServiceConfig struct {
ErrorHandler ErrorHandler
}
func GetDefaultConfig ¶
func GetDefaultConfig() EventServiceConfig
Returns default config for events service
type ListenerDestroyer ¶
type ListenerDestroyer func()