scheduleFire arms or extends a single debounce timer.
()
| 326 | |
| 327 | // scheduleFire arms or extends a single debounce timer. |
| 328 | func (cw *configWatcher) scheduleFire() { |
| 329 | cw.mu.Lock() |
| 330 | defer cw.mu.Unlock() |
| 331 | if cw.closed { |
| 332 | return |
| 333 | } |
| 334 | if cw.timer != nil { |
| 335 | // Reset existing timer to extend the debounce window. |
| 336 | // Stop reports whether the call stopped the timer before |
| 337 | // it fired; if so we owe a Done because Add was called |
| 338 | // when the timer was created. |
| 339 | if cw.timer.Stop() { |
| 340 | cw.firesWG.Done() |
| 341 | } |
| 342 | } |
| 343 | cw.firesWG.Add(1) |
| 344 | cw.timer = cw.clock.AfterFunc(cw.debounce, cw.fire, "agentmcp", "watch_debounce") |
| 345 | } |
| 346 | |
| 347 | // fire is called once per debounce window. It invokes onChange |
| 348 | // outside the lock so reload code can re-enter Sync safely. |