MCPcopy Create free account
hub / github.com/apache/casbin-etcd-watcher / startWatch

Method startWatch

watcher.go:164–186  ·  view source on GitHub ↗

startWatch is a goroutine that watches the policy change.

()

Source from the content-addressed store, hash-verified

162
163// startWatch is a goroutine that watches the policy change.
164func (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}

Callers 2

NewWatcherFunction · 0.95
NewWatcherWithConfigFunction · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected