summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2020-10-25 15:55:51 +0300
committerWolfy-J <[email protected]>2020-10-25 15:55:51 +0300
commitba5c562f9038ba434e655fb82c44597fcccaff16 (patch)
treeff112b9dcffda63bc40094a57d0df61622368445 /util
parent3bdf7d02d83d1ff4726f3fbb01a45d016f39abec (diff)
- massive update in roadrunner 2.0 abstractions
Diffstat (limited to 'util')
-rw-r--r--util/events.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/util/events.go b/util/events.go
new file mode 100644
index 00000000..9e12c4f7
--- /dev/null
+++ b/util/events.go
@@ -0,0 +1,26 @@
+package util
+
+// Event listener listens for the events produced by worker, worker pool or other servce.
+type EventListener func(event interface{})
+
+// EventHandler helps to broadcast events to multiple listeners.
+type EventHandler struct {
+ listeners []EventListener
+}
+
+// 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 EventListener) {
+ eb.listeners = append(eb.listeners, listener)
+}
+
+// Push broadcast events across all event listeners.
+func (eb *EventHandler) Push(e interface{}) {
+ for _, listener := range eb.listeners {
+ listener(e)
+ }
+}