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