diff options
author | Valery Piashchynski <[email protected]> | 2020-12-17 10:19:01 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2020-12-17 10:19:01 +0300 |
commit | acb53196f8ff4518c515225b39c6fb2bac64faae (patch) | |
tree | 3c016e03132a38ec3dd3fce737120a0fdc9642c9 /util | |
parent | 8422e300f64f20d86ffccf773d41109285bbc12d (diff) |
Update events handler, add mutex to push
Diffstat (limited to 'util')
-rwxr-xr-x | util/events.go | 36 |
1 files changed, 0 insertions, 36 deletions
diff --git a/util/events.go b/util/events.go deleted file mode 100755 index dbb5990b..00000000 --- a/util/events.go +++ /dev/null @@ -1,36 +0,0 @@ -package util - -import ( - "sync" - - "github.com/spiral/roadrunner/v2/interfaces/events" -) - -// EventHandler helps to broadcast events to multiple listeners. -type EventHandler struct { - listeners []events.EventListener - sync.RWMutex -} - -func NewEventsHandler() events.Handler { - return &EventHandler{listeners: make([]events.EventListener, 0, 2)} -} - -// NumListeners returns number of event listeners. -func (eb *EventHandler) NumListeners() int { - return len(eb.listeners) -} - -// AddListener registers new event listener. -func (eb *EventHandler) AddListener(listener events.EventListener) { - eb.Lock() - defer eb.Unlock() - eb.listeners = append(eb.listeners, listener) -} - -// Push broadcast events across all event listeners. -func (eb *EventHandler) Push(e interface{}) { - for k := range eb.listeners { - eb.listeners[k](e) - } -} |