2019-01-18 17:29:17 +00:00
|
|
|
package memory
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
2020-01-30 14:39:00 +03:00
|
|
|
"github.com/micro/go-micro/v2/registry"
|
2019-01-18 17:29:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Watcher struct {
|
|
|
|
id string
|
|
|
|
wo registry.WatchOptions
|
|
|
|
res chan *registry.Result
|
|
|
|
exit chan bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Watcher) Next() (*registry.Result, error) {
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case r := <-m.res:
|
|
|
|
if len(m.wo.Service) > 0 && m.wo.Service != r.Service.Name {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
return r, nil
|
|
|
|
case <-m.exit:
|
|
|
|
return nil, errors.New("watcher stopped")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Watcher) Stop() {
|
|
|
|
select {
|
|
|
|
case <-m.exit:
|
|
|
|
return
|
|
|
|
default:
|
|
|
|
close(m.exit)
|
|
|
|
}
|
|
|
|
}
|