mirror of
https://github.com/mainnika/nodesync.git
synced 2026-05-23 16:23:34 +00:00
Implement function to wait node to be empty
This commit is contained in:
+24
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user