2020-02-08 17:01:47 +05:30
|
|
|
package dispatcher
|
|
|
|
|
|
|
|
import "github.com/asaskevich/EventBus"
|
|
|
|
|
|
|
|
type EventDispatcher interface {
|
2020-02-16 15:53:47 +05:30
|
|
|
Subscribe(topic string, fn interface{})
|
|
|
|
Emit(topic string, args ...interface{})
|
2020-02-08 17:01:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
type LocalEventDispatcher struct {
|
|
|
|
bus EventBus.Bus
|
|
|
|
}
|
|
|
|
|
2020-02-16 15:53:47 +05:30
|
|
|
func (d *LocalEventDispatcher) Subscribe(topic string, fn interface{}) {
|
|
|
|
_ = d.bus.Subscribe(topic, fn)
|
2020-02-08 17:01:47 +05:30
|
|
|
}
|
|
|
|
|
2020-02-16 15:53:47 +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 {
|
|
|
|
return &LocalEventDispatcher{
|
|
|
|
bus: EventBus.New(),
|
|
|
|
}
|
|
|
|
}
|