startWatch is a goroutine that watches the policy change.
()
| 162 | |
| 163 | // startWatch is a goroutine that watches the policy change. |
| 164 | func (w *Watcher) startWatch() error { |
| 165 | watcher := w.client.Watch(context.Background(), w.keyName) |
| 166 | for res := range watcher { |
| 167 | // Skip progress notifications |
| 168 | if res.IsProgressNotify() { |
| 169 | continue |
| 170 | } |
| 171 | // Skip empty events |
| 172 | if len(res.Events) == 0 { |
| 173 | continue |
| 174 | } |
| 175 | t := res.Events[0] |
| 176 | if t.IsCreate() || t.IsModify() { |
| 177 | w.lock.RLock() |
| 178 | //ignore self update |
| 179 | if rev := t.Kv.ModRevision; rev > w.lastSentRev && w.callback != nil { |
| 180 | w.callback(strconv.FormatInt(rev, 10)) |
| 181 | } |
| 182 | w.lock.RUnlock() |
| 183 | } |
| 184 | } |
| 185 | return nil |
| 186 | } |
no outgoing calls
no test coverage detected