Split Dispatcher interface and use it across application

This commit is contained in:
ErickSkrauch
2020-04-20 14:29:33 +03:00
parent f58b980948
commit 2ea4c55d37
5 changed files with 22 additions and 27 deletions

View File

@@ -2,12 +2,19 @@ package dispatcher
import "github.com/asaskevich/EventBus"
// TODO: split on 2 interfaces and use them across the application
type EventDispatcher interface {
type Subscriber interface {
Subscribe(topic string, fn interface{})
}
type Emitter interface {
Emit(topic string, args ...interface{})
}
type Dispatcher interface {
Subscriber
Emitter
}
type localEventDispatcher struct {
bus EventBus.Bus
}
@@ -20,7 +27,7 @@ func (d *localEventDispatcher) Emit(topic string, args ...interface{}) {
d.bus.Publish(topic, args...)
}
func New() EventDispatcher {
func New() Dispatcher {
return &localEventDispatcher{
bus: EventBus.New(),
}