Documentation ¶
Overview ¶
Package emitter implements channel based pubsub pattern. The design goals are:
- fully functional and safety
- simple to understand and use
- make the code readable, maintainable and minimalistic
Index ¶
- func Once(e Event)
- func Skip(e Event)
- func Test(pattern string) bool
- func Void(e Event)
- type BasicEvent
- type Emitter
- func (e *Emitter) Emit(event Event) chan struct{}
- func (e *Emitter) Listeners(topic string) []Listener
- func (e *Emitter) Off(topic string, listeners ...Listener)
- func (e *Emitter) On(topic string, listener Listener, middlewares ...func(Event))
- func (e *Emitter) Once(topic string, listener Listener, middlewares ...func(Event))
- func (e *Emitter) Topics() []string
- func (e *Emitter) Use(pattern string, middlewares ...func(Event))
- type Event
- type EventOf
- type Flag
- type Listener
- type ListenerFunc
- type ListenerFuncOf
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Test ¶
Test returns boolean value to indicate that given pattern is valid.
What is it for? Internally `emitter` uses `path.Match` function to find matching. But as this functionality is optional `Emitter` don't indicate that the pattern is invalid. You should check it separately explicitly via `Test` function.
Types ¶
type BasicEvent ¶
type BasicEvent struct {
// contains filtered or unexported fields
}
func NewEvent ¶
func NewEvent(topic string, subject any) *BasicEvent
func (*BasicEvent) Clone ¶
func (e *BasicEvent) Clone() Event
func (*BasicEvent) Flag ¶
func (e *BasicEvent) Flag() Flag
func (*BasicEvent) SetFlag ¶
func (e *BasicEvent) SetFlag(flag Flag)
func (*BasicEvent) Subject ¶
func (e *BasicEvent) Subject() any
func (*BasicEvent) Topic ¶
func (e *BasicEvent) Topic() string
type Emitter ¶
type Emitter struct { Cap uint // contains filtered or unexported fields }
Emitter is a struct that allows to emit, receive event, close receiver channel, get info about topics and listMans
func New ¶
New returns just created Emitter struct. Capacity argument will be used to create channels with given capacity
func (*Emitter) Emit ¶
Emit emits an event with the rest arguments to all listMans which were covered by topic(it can be pattern).
func (*Emitter) Listeners ¶
Listeners returns slice of listMans which were covered by topic(it can be pattern) and error if pattern is invalid.
func (*Emitter) Off ¶
Off unsubscribes all listMans which were covered by topic, it can be pattern as well.
func (*Emitter) On ¶
On returns a channel that will receive events. As optional second argument it takes middlewares.
type Event ¶
type Event interface { // Topic returns the topic of the event. Topic() string // Flag returns the flag of the event. Flag() Flag // SetFlag sets the flag of the event. SetFlag(Flag) // Subject returns the subject of the event. Subject() any // Clone returns a copy of the event. Clone() Event }
Event is an interface used to pass events to listeners.
type EventOf ¶
type EventOf[T any] struct { // contains filtered or unexported fields }
func NewEventOf ¶
func (*EventOf[T]) TypedSubject ¶
func (e *EventOf[T]) TypedSubject() T
type ListenerFunc ¶
type ListenerFunc func(Event)
func (ListenerFunc) Observe ¶ added in v1.1.0
func (fn ListenerFunc) Observe(e Event)
type ListenerFuncOf ¶
func (ListenerFuncOf[T]) Observe ¶ added in v1.1.0
func (fn ListenerFuncOf[T]) Observe(e Event)