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