mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
refactor(watcher_hub.go) refactor notifyWatchers()
This commit is contained in:
parent
59ccefee0f
commit
d66dc3c1c7
@ -113,31 +113,26 @@ func (wh *watcherHub) notifyWatchers(e *Event, path string, deleted bool) {
|
|||||||
if ok {
|
if ok {
|
||||||
curr := l.Front()
|
curr := l.Front()
|
||||||
|
|
||||||
for {
|
for curr != nil {
|
||||||
if curr == nil { // we have reached the end of the list
|
|
||||||
if l.Len() == 0 {
|
|
||||||
// if we have notified all watcher in the list
|
|
||||||
// we can delete the list
|
|
||||||
delete(wh.watchers, path)
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
next := curr.Next() // save reference to the next one in the list
|
next := curr.Next() // save reference to the next one in the list
|
||||||
|
|
||||||
w, _ := curr.Value.(*Watcher)
|
w, _ := curr.Value.(*Watcher)
|
||||||
|
|
||||||
if w.notify(e, e.Node.Key == path, deleted) {
|
if w.notify(e, e.Node.Key == path, deleted) {
|
||||||
|
|
||||||
// if we successfully notify a watcher
|
// if we successfully notify a watcher
|
||||||
// we need to remove the watcher from the list
|
// we need to remove the watcher from the list
|
||||||
// and decrease the counter
|
// and decrease the counter
|
||||||
l.Remove(curr)
|
l.Remove(curr)
|
||||||
atomic.AddInt64(&wh.count, -1)
|
atomic.AddInt64(&wh.count, -1)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
curr = next // update current to the next
|
curr = next // update current to the next element in the list
|
||||||
|
}
|
||||||
|
|
||||||
|
if l.Len() == 0 {
|
||||||
|
// if we have notified all watcher in the list
|
||||||
|
// we can delete the list
|
||||||
|
delete(wh.watchers, path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user