summaryrefslogtreecommitdiffhomepage
path: root/go/observable.go
diff options
context:
space:
mode:
Diffstat (limited to 'go/observable.go')
-rw-r--r--go/observable.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/go/observable.go b/go/observable.go
new file mode 100644
index 00000000..9a38802c
--- /dev/null
+++ b/go/observable.go
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) NGINX, Inc.
+ */
+
+package unit
+
+import (
+ "sync"
+)
+
+type observable struct {
+ sync.Mutex
+ observers []chan int
+}
+
+func (o *observable) attach(c chan int) {
+ o.Lock()
+ defer o.Unlock()
+
+ o.observers = append(o.observers, c)
+}
+
+func (o *observable) notify(e int) {
+ o.Lock()
+ defer o.Unlock()
+
+ for _, v := range o.observers {
+ v <- e
+ }
+
+ o.observers = nil
+}