chrly/dispatcher/dispatcher.go

27 lines
538 B
Go
Raw Normal View History

2020-02-08 17:01:47 +05:30
package dispatcher
import "github.com/asaskevich/EventBus"
type EventDispatcher interface {
Subscribe(topic string, fn interface{})
Emit(topic string, args ...interface{})
2020-02-08 17:01:47 +05:30
}
2020-04-16 22:12:38 +05:30
type localEventDispatcher struct {
2020-02-08 17:01:47 +05:30
bus EventBus.Bus
}
2020-04-16 22:12:38 +05:30
func (d *localEventDispatcher) Subscribe(topic string, fn interface{}) {
_ = d.bus.Subscribe(topic, fn)
2020-02-08 17:01:47 +05:30
}
2020-04-16 22:12:38 +05:30
func (d *localEventDispatcher) Emit(topic string, args ...interface{}) {
d.bus.Publish(topic, args...)
2020-02-08 17:01:47 +05:30
}
func New() EventDispatcher {
2020-04-16 22:12:38 +05:30
return &localEventDispatcher{
2020-02-08 17:01:47 +05:30
bus: EventBus.New(),
}
}