Closed learnd closed 4 months ago
func (s EtcdV3) WatchTree(directory string, stopCh <-chan struct{}) (<-chan []store.KVPair, error) { watchCh := make(chan []*store.KVPair)
go func() { defer close(watchCh) list, err := s.List(directory) if err != nil { if !s.AllowKeyNotFound || err != store.ErrKeyNotFound { return } } watchCh <- list rch := s.client.Watch(context.Background(), directory, clientv3.WithPrefix()) for { select { case <-s.done: return case resp := <-rch: if resp.Canceled { // watch is canceled return } list, err := s.List(directory) if err != nil { if !s.AllowKeyNotFound || err != store.ErrKeyNotFound { continue } } watchCh <- list } } }()
rch被关掉,导致case resp := <-rch:无限循环执行
func (s EtcdV3) WatchTree(directory string, stopCh <-chan struct{}) (<-chan []store.KVPair, error) { watchCh := make(chan []*store.KVPair)
rch被关掉,导致case resp := <-rch:无限循环执行