Remove the table watcher when stopped
This commit is contained in:
parent
d7929ef8f3
commit
6719f8d655
@ -160,13 +160,23 @@ func (t *table) Watch(opts ...WatchOption) (Watcher, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
w := &tableWatcher{
|
w := &tableWatcher{
|
||||||
|
id: uuid.New().String(),
|
||||||
opts: wopts,
|
opts: wopts,
|
||||||
resChan: make(chan *Event, 10),
|
resChan: make(chan *Event, 10),
|
||||||
done: make(chan struct{}),
|
done: make(chan struct{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// when the watcher is stopped delete it
|
||||||
|
go func() {
|
||||||
|
<-w.done
|
||||||
t.Lock()
|
t.Lock()
|
||||||
t.watchers[uuid.New().String()] = w
|
delete(t.watchers, w.id)
|
||||||
|
t.Unlock()
|
||||||
|
}()
|
||||||
|
|
||||||
|
// save the watcher
|
||||||
|
t.Lock()
|
||||||
|
t.watchers[w.id] = w
|
||||||
t.Unlock()
|
t.Unlock()
|
||||||
|
|
||||||
return w, nil
|
return w, nil
|
||||||
|
@ -72,6 +72,7 @@ func WatchService(s string) WatchOption {
|
|||||||
|
|
||||||
type tableWatcher struct {
|
type tableWatcher struct {
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
|
id string
|
||||||
opts WatchOptions
|
opts WatchOptions
|
||||||
resChan chan *Event
|
resChan chan *Event
|
||||||
done chan struct{}
|
done chan struct{}
|
||||||
|
Loading…
Reference in New Issue
Block a user