You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ims/util/evio/default.go

46 lines
810 B

package evio
import (
"context"
"sync/atomic"
)
var defaultEvio atomic.Pointer[simple]
func init() {
evio := New(NewMatcher).(*simple)
defaultEvio.Store(evio)
}
func Default() Evio {
return defaultEvio.Load()
}
func Call(topic string, data any) {
Default().Call(topic, data)
}
func Publish(topic string, data any) error {
return Default().Publish(topic, data)
}
func Subscribe(topic string, handler Handler, opts ...SubscribeOption) (func() bool, error) {
return Default().Subscribe(topic, handler, opts...)
}
func Listen(topic string) (stop func(), data <-chan any, err error) {
return Default().Listen(topic)
}
func Start(ctx context.Context) error {
select {
case <-ctx.Done():
return ctx.Err()
default:
return Default().Start()
}
}
func Stop() error {
return Default().Stop()
}