summaryrefslogtreecommitdiff
path: root/internal/events/events.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/events/events.go')
-rw-r--r--internal/events/events.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/internal/events/events.go b/internal/events/events.go
new file mode 100644
index 0000000..49731b8
--- /dev/null
+++ b/internal/events/events.go
@@ -0,0 +1,34 @@
+package events
+
+import (
+ "sync"
+
+ "go.neonxp.dev/djson/internal/model"
+)
+
+type stdDispatcher struct {
+ tree subscriberNode
+}
+
+func New() Dispatcher {
+ return &stdDispatcher{
+ tree: subscriberNode{
+ children: make(map[string]*subscriberNode),
+ channels: make(map[string]chan model.Mutation),
+ parent: nil,
+ mu: sync.RWMutex{},
+ },
+ }
+}
+
+func (ed *stdDispatcher) Subscribe(path []string, id string, ch chan model.Mutation) {
+ ed.tree.subscribe(path, id, ch)
+}
+
+func (ed *stdDispatcher) Unsubscribe(path []string, id string) {
+ ed.tree.unsubscribe(path, id)
+}
+
+func (ed *stdDispatcher) Notify(path []string, event *model.Mutation) {
+ ed.tree.notify(path, event)
+}