summaryrefslogtreecommitdiff
path: root/internal/events/events.go
blob: 49731b89cf67d745a674d9262a3e289c31f942fc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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)
}