chrly/dispatcher/dispatcher.go
2020-02-08 14:31:47 +03:00

27 lines
532 B
Go

package dispatcher
import "github.com/asaskevich/EventBus"
type EventDispatcher interface {
Subscribe(name string, fn interface{})
Emit(name string, args ...interface{})
}
type LocalEventDispatcher struct {
bus EventBus.Bus
}
func (d *LocalEventDispatcher) Subscribe(name string, fn interface{}) {
_ = d.bus.Subscribe(name, fn)
}
func (d *LocalEventDispatcher) Emit(name string, args ...interface{}) {
d.bus.Publish(name, args...)
}
func New() EventDispatcher {
return &LocalEventDispatcher{
bus: EventBus.New(),
}
}