From aca7879178be0e6c9c171896b11c49b29d19663e Mon Sep 17 00:00:00 2001 From: Nikita Tokarchuk Date: Wed, 13 Apr 2022 23:50:12 +0200 Subject: [PATCH] Implement function to wait node for any changes --- nodesync.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/nodesync.go b/nodesync.go index c0fb065..7b6bb11 100644 --- a/nodesync.go +++ b/nodesync.go @@ -160,4 +160,20 @@ func (s *NodeSync) WaitEmpty(where string) (err error) { } return -} \ No newline at end of file +} + +// 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 +}