mirror of
https://github.com/mainnika/nodesync.git
synced 2026-06-13 00:43:33 +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)
|
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
|
return
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user