summaryrefslogtreecommitdiff
path: root/util/events.go
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2020-11-16 15:46:08 +0300
committerGitHub <[email protected]>2020-11-16 15:46:08 +0300
commit6236aac37bd1661b20400689f66d1e92283c5111 (patch)
treeeb8a9a4e4717fb4cd6c971b5ce67c53b5f6a0f8c /util/events.go
parent0874bcb2f6b284a940ba4f3507eb8c4619c27868 (diff)
parent38f6925db27dd94cfbca873901bf932ed1456906 (diff)
Merge pull request #392 from spiral/plugin/metricsv2.0.0-alpha18
[RR2] Metrics plugin 2.0
Diffstat (limited to 'util/events.go')
-rwxr-xr-xutil/events.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/util/events.go b/util/events.go
index 9e12c4f7..21ebc29b 100755
--- a/util/events.go
+++ b/util/events.go
@@ -1,5 +1,11 @@
package util
+type EventsHandler interface {
+ NumListeners() int
+ AddListener(listener EventListener)
+ Push(e interface{})
+}
+
// Event listener listens for the events produced by worker, worker pool or other servce.
type EventListener func(event interface{})
@@ -8,6 +14,10 @@ type EventHandler struct {
listeners []EventListener
}
+func NewEventsHandler() EventsHandler {
+ return &EventHandler{listeners: make([]EventListener, 0, 2)}
+}
+
// NumListeners returns number of event listeners.
func (eb *EventHandler) NumListeners() int {
return len(eb.listeners)