Merge pull request #852 from abronan/fix_zookeeper_watch

Fix zookeeper watch that was triggered only once
This commit is contained in:
Andrea Luzzardi 2015-05-26 15:23:47 -07:00
commit d4672005bf
1 changed files with 7 additions and 7 deletions

View File

@ -157,7 +157,7 @@ func (s *Zookeeper) Watch(key string, stopCh <-chan struct{}) (<-chan *KVPair, e
// Providing a non-nil stopCh can be used to stop watching.
func (s *Zookeeper) WatchTree(prefix string, stopCh <-chan struct{}) (<-chan []*KVPair, error) {
fprefix := normalize(prefix)
entries, stat, eventCh, err := s.client.ChildrenW(fprefix)
entries, err := s.List(prefix)
if err != nil {
return nil, err
}
@ -167,14 +167,14 @@ func (s *Zookeeper) WatchTree(prefix string, stopCh <-chan struct{}) (<-chan []*
go func() {
defer close(watchCh)
// GetW returns the current value before setting the watch.
kv := []*KVPair{}
for _, item := range entries {
kv = append(kv, &KVPair{prefix, []byte(item), uint64(stat.Mzxid)})
}
watchCh <- kv
// List returns the current values before setting the watch.
watchCh <- entries
for {
_, _, eventCh, err := s.client.ChildrenW(fprefix)
if err != nil {
return
}
select {
case e := <-eventCh:
if e.Type == zk.EventNodeChildrenChanged {