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 Close(e *Event)
- func Once(e *Event)
- func Reset(e *Event)
- func Skip(e *Event)
- func Sync(e *Event)
- func Test(pattern string) bool
- func Void(e *Event)
- type Emitter
- func (e *Emitter) Emit(topic string, args ...interface{}) chan struct{}
- func (e *Emitter) Listeners(topic string) []<-chan Event
- func (e *Emitter) Off(topic string, channels ...<-chan Event)
- func (e *Emitter) On(topic string, middlewares ...func(*Event)) <-chan Event
- func (e *Emitter) OnWithCap(topic string, capacity uint, middlewares ...func(*Event)) <-chan Event
- func (e *Emitter) Once(topic string, middlewares ...func(*Event)) <-chan Event
- func (e *Emitter) Topics() []string
- func (e *Emitter) Use(pattern string, middlewares ...func(*Event))
- type Event
- type Flag
- type Group
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 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 listeners
func New ¶
New returns just created Emitter struct. Capacity argument will be used to create channels with given capacity by default. The OnWithCap method can be used to get different capacities per listener.
func (*Emitter) Emit ¶
Emit emits an event with the rest arguments to all listeners which were covered by topic(it can be pattern).
func (*Emitter) Listeners ¶
Listeners returns slice of listeners which were covered by topic(it can be pattern) and error if pattern is invalid.
func (*Emitter) Off ¶
Off unsubscribes all listeners 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.
func (*Emitter) OnWithCap ¶
On returns a channel that will receive events with the listener capacity specified. As optional second argument it takes middlewares.
type Event ¶
Event is a structure to send events contains some helpers to cast primitive types easily.
func (Event) Bool ¶
Bool returns casted into bool type argument by index. `dflt` argument is an optional default value returned either in case of casting error or in case of index error.
func (Event) Float ¶
Float returns casted into float64 type argument by index. `dflt` argument is an optional default value returned either in case of casting error or in case of index error.
type Flag ¶
type Flag int
Flag used to describe what behavior do you expect.
const ( // FlagReset only to clear previously defined flags. // Example: // ee.Use("*", Reset) // clears flags for this pattern FlagReset Flag = 0 // FlagOnce indicates to remove the listener after first sending. FlagOnce Flag = 1 << iota // FlagVoid indicates to skip sending. FlagVoid // FlagSkip indicates to skip sending if channel is blocked. FlagSkip // FlagClose indicates to drop listener if channel is blocked. FlagClose // FlagSync indicates to send an event synchronously. FlagSync )
type Group ¶
type Group struct { // Cap is capacity to create new channel Cap uint // contains filtered or unexported fields }
Group marges given subscribed channels into on subscribed channel
func (*Group) Flush ¶
func (g *Group) Flush()
Flush reset the group to the initial state. All references will dropped.