github.com/volts-dev/volts@v0.0.0-20240120094013-5e9c65924106/registry/memory/watcher.go (about) 1 package memory 2 3 import ( 4 "errors" 5 6 "github.com/volts-dev/volts/registry" 7 ) 8 9 type memWatcher struct { 10 wo registry.WatchConfig 11 res chan *registry.Result 12 exit chan bool 13 id string 14 } 15 16 func (m *memWatcher) 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 *memWatcher) Stop() { 31 select { 32 case <-m.exit: 33 return 34 default: 35 close(m.exit) 36 } 37 }