Fix zookeeper watch that was triggered only once

Signed-off-by: Alexandre Beslic <abronan@docker.com>
This commit is contained in:
Alexandre Beslic 2015-05-26 14:59:38 -07:00
parent 0b24992d7c
commit dedb0ed906
1 changed files with 6 additions and 6 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
}
@ -168,13 +168,13 @@ func (s *Zookeeper) WatchTree(prefix string, stopCh <-chan struct{}) (<-chan []*
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
watchCh <- entries
for {
_, _, eventCh, err := s.client.ChildrenW(fprefix)
if err != nil {
return
}
select {
case e := <-eventCh:
if e.Type == zk.EventNodeChildrenChanged {