Implement function to wait node to be empty

This commit is contained in:
2022-04-13 23:49:57 +02:00
parent 8977dfc920
commit e09930bab7
+24
View File
@@ -135,5 +135,29 @@ func (s *NodeSync) Unlock(where string, iam string) (err error) {
err = s.Zk.Delete(path.Join(workingPath, iam), 0)
return
}
// WaitEmpty implements a barrier synchronisation mechanism by waiting for empty node.
func (s *NodeSync) WaitEmpty(where string) (err error) {
workingPath := path.Join(s.rootPath, where)
for {
var children []string
var ev <-chan zk.Event
children, _, ev, err = s.Zk.ChildrenW(workingPath)
if err != nil {
return
}
if len(children) == 0 {
break
}
<-ev
}
return
}