mirror of
https://github.com/elyby/chrly.git
synced 2025-05-31 14:11:51 +05:30
Implemented event dispatcher
This commit is contained in:
26
dispatcher/dispatcher.go
Normal file
26
dispatcher/dispatcher.go
Normal 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(),
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user