You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
wg-access-server/internal/storage/inprocesswatcher.go

38 lines
698 B
Go

package storage
type InProcessWatcher struct {
add []Callback
delete []Callback
}
func NewInProcessWatcher() *InProcessWatcher {
return &InProcessWatcher{
add: []Callback{},
delete: []Callback{},
}
}
func (w *InProcessWatcher) OnAdd(cb Callback) {
w.add = append(w.add, cb)
}
func (w *InProcessWatcher) OnDelete(cb Callback) {
w.delete = append(w.delete, cb)
}
func (w *InProcessWatcher) OnReconnect(cb func()) {
// noop because the inprocess watcher can't disconnect
}
func (w *InProcessWatcher) emitAdd(device *Device) {
for _, cb := range w.add {
cb(device)
}
}
func (w *InProcessWatcher) emitDelete(device *Device) {
for _, cb := range w.delete {
cb(device)
}
}