Move memory to gossip since that's what it is

This commit is contained in:
Asim
2016-05-06 19:56:02 +01:00
committed by Vasiliy Tolstov
commit 0c6951b47e
4 changed files with 635 additions and 0 deletions

47
watch.go Normal file
View File

@@ -0,0 +1,47 @@
package gossip
import (
"errors"
"github.com/micro/go-micro/registry"
)
type gossipWatcher struct {
next chan *registry.Result
stop chan bool
}
func newGossipWatcher(ch chan *registry.Result, exit chan bool) (registry.Watcher, error) {
stop := make(chan bool)
go func() {
<-stop
close(exit)
}()
return &gossipWatcher{
next: ch,
stop: stop,
}, nil
}
func (m *gossipWatcher) Next() (*registry.Result, error) {
select {
case r, ok := <-m.next:
if !ok {
return nil, errors.New("result chan closed")
}
return r, nil
case <-m.stop:
return nil, errors.New("watcher stopped")
}
}
func (m *gossipWatcher) Stop() {
select {
case <-m.stop:
return
default:
close(m.stop)
}
}