1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-11-30 08:06:40 +02:00
go-micro/registry/memory_watcher.go
2020-12-29 15:49:26 +00:00

36 lines
488 B
Go

package registry
import (
"errors"
)
type memWatcher struct {
id string
wo WatchOptions
res chan *Result
exit chan bool
}
func (m *memWatcher) Next() (*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 *memWatcher) Stop() {
select {
case <-m.exit:
return
default:
close(m.exit)
}
}