gitee.com/liuxuezhan/go-micro-v1.18.0@v1.0.0/registry/memory/watcher.go (about) 1 package memory 2 3 import ( 4 "errors" 5 6 "gitee.com/liuxuezhan/go-micro-v1.18.0/registry" 7 ) 8 9 type Watcher struct { 10 id string 11 wo registry.WatchOptions 12 res chan *registry.Result 13 exit chan bool 14 } 15 16 func (m *Watcher) Next() (*registry.Result, error) { 17 for { 18 select { 19 case r := <-m.res: 20 if len(m.wo.Service) > 0 && m.wo.Service != r.Service.Name { 21 continue 22 } 23 return r, nil 24 case <-m.exit: 25 return nil, errors.New("watcher stopped") 26 } 27 } 28 } 29 30 func (m *Watcher) Stop() { 31 select { 32 case <-m.exit: 33 return 34 default: 35 close(m.exit) 36 } 37 }