Documentation ¶
Overview ¶
eventtbus is a package for a simple event bus.
Index ¶
- Variables
- func AddObserver(o observer, opts ...observerOpt) string
- func Close()
- func Flush(ctx context.Context)
- func New(opts ...busOpt) *bus
- func On(name Stringer) *subscription
- func Publish(ctx context.Context, name Stringer, data interface{}, opts ...eventOpt) error
- func RegexMatcher(s string) (regexMatcher, error)
- func RemoveObserver(id string) bool
- func SetDefault(eb *bus)
- func Wait(ctx context.Context)
- func When(matchers ...Matcher) *subscription
- func WildcardMatcher(s string) regexMatcher
- type Errors
- type Event
- type Matcher
- type PredicateMatcher
- type StringMatcher
- type Stringer
Constants ¶
This section is empty.
Variables ¶
var ( WithMaxConcurrencyBusOpt = func(c int64) busOpt { return func(b *bus) { if c < 1 { c = 1 } b.concurrency = c } } WithContinueOnErrorBusOpt = func() busOpt { return func(b *bus) { b.continueOnError = true } } )
Bus options
var ( WithHandlerTimeoutEventOpt = func(d time.Duration) eventOpt { return func(e *Event) { e.handlerTimeout = d } } WithPublishTimeoutEventOpt = func(d time.Duration) eventOpt { return func(e *Event) { e.publishTimeout = d } } )
Event options
var (
ErrBusClosed = errors.New("bus is closed")
)
var (
WithTimeoutObserverOpt = func(d time.Duration) observerOpt {
return func(o *observerOptions) {
o.timeout = d
}
}
)
Observer options
Functions ¶
func AddObserver ¶
func AddObserver(o observer, opts ...observerOpt) string
Adds an observer. Observers are notified of all published events, and are executed in parallel.
func On ¶
func On(name Stringer) *subscription
On subscribes to an event by name in the default event bus.
func RegexMatcher ¶
RegexMatcher is a string that utilizes a regular expression to match events.
func When ¶
func When(matchers ...Matcher) *subscription
When subscribes to an event by arbitrary matchers in the default event bus.
func WildcardMatcher ¶
func WildcardMatcher(s string) regexMatcher
WildcardMatcher is a string that utilizes the asterisk (*) as a wildcard character. It can match all events with "*", all events with a prefix "foo*", all events with a suffix "*bar", all events with a substring "foo*bar", or a combination of the above. A question mark (?) can be used to match a single character.
Types ¶
type PredicateMatcher ¶
PredicateMatcher is a function that accepts an event name and data and returns true if the event matches the predicate.
func ExactMatcher ¶
func ExactMatcher(thisName Stringer) PredicateMatcher
ExactMatcher is matcher that matches events by equality.
func (PredicateMatcher) Match ¶
func (m PredicateMatcher) Match(name Stringer, data interface{}) bool
func (PredicateMatcher) String ¶
func (m PredicateMatcher) String() string
type StringMatcher ¶
type StringMatcher string
StringMatcher is a string that matches events by name, ignoring case and type.
func (StringMatcher) Match ¶
func (m StringMatcher) Match(name Stringer, data interface{}) bool
func (StringMatcher) String ¶
func (m StringMatcher) String() string