mirror of
https://github.com/mainnika/nodesync.git
synced 2026-05-22 15:53:34 +00:00
Implement function to wait node for any changes
This commit is contained in:
+17
-1
@@ -160,4 +160,20 @@ func (s *NodeSync) WaitEmpty(where string) (err error) {
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// WaitChanged waits for any changes a zookeeper node and returns a new children list after the change.
|
||||
// Note: the children list is always stable sorted.
|
||||
func (s *NodeSync) WaitChanged(where string) (children []string, ev <-chan zk.Event, err error) {
|
||||
|
||||
workingPath := path.Join(s.rootPath, where)
|
||||
|
||||
children, _, ev, err = s.Zk.ChildrenW(workingPath)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
children = sortChildren(children)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user