Implemented event dispatcher

This commit is contained in:
ErickSkrauch
2020-02-08 14:31:47 +03:00
parent 2abe2db469
commit db728451f8
6 changed files with 55 additions and 6 deletions

26
dispatcher/dispatcher.go Normal file
View File

@@ -0,0 +1,26 @@
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(),
}
}