2020-12-29 17:49:26 +02:00
|
|
|
package registry
|
2019-01-18 19:29:17 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
)
|
|
|
|
|
2020-12-29 17:49:26 +02:00
|
|
|
type memWatcher struct {
|
|
|
|
wo WatchOptions
|
|
|
|
res chan *Result
|
2019-01-18 19:29:17 +02:00
|
|
|
exit chan bool
|
2023-04-26 02:16:34 +02:00
|
|
|
id string
|
2019-01-18 19:29:17 +02:00
|
|
|
}
|
|
|
|
|
2020-12-29 17:49:26 +02:00
|
|
|
func (m *memWatcher) Next() (*Result, error) {
|
2019-01-18 19:29:17 +02:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-29 17:49:26 +02:00
|
|
|
func (m *memWatcher) Stop() {
|
2019-01-18 19:29:17 +02:00
|
|
|
select {
|
|
|
|
case <-m.exit:
|
|
|
|
return
|
|
|
|
default:
|
|
|
|
close(m.exit)
|
|
|
|
}
|
|
|
|
}
|