summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xpkg/worker_watcher/worker_watcher.go2
-rwxr-xr-xutil/events.go9
2 files changed, 10 insertions, 1 deletions
diff --git a/pkg/worker_watcher/worker_watcher.go b/pkg/worker_watcher/worker_watcher.go
index 8a71ff8a..8788e509 100755
--- a/pkg/worker_watcher/worker_watcher.go
+++ b/pkg/worker_watcher/worker_watcher.go
@@ -172,7 +172,7 @@ func (ww *workerWatcher) AddToWatch(workers []worker.BaseProcess) error {
go func(swc worker.BaseProcess) {
ww.wait(swc)
- }(workers[i])
+ }(sw)
}
return nil
}
diff --git a/util/events.go b/util/events.go
index 259c7ddb..676e2f40 100755
--- a/util/events.go
+++ b/util/events.go
@@ -1,12 +1,15 @@
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.Mutex
}
func NewEventsHandler() events.Handler {
@@ -15,16 +18,22 @@ func NewEventsHandler() events.Handler {
// NumListeners returns number of event listeners.
func (eb *EventHandler) NumListeners() int {
+ eb.Lock()
+ defer eb.Unlock()
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{}) {
+ eb.Lock()
+ defer eb.Unlock()
for _, listener := range eb.listeners {
listener(e)
}