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.
38 lines
698 B
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)
|
|
}
|
|
}
|