updateRoutine is responsible for informing the server of worthy changes to our local state. It runs in its own goroutine.
()
| 55 | // updateRoutine is responsible for informing the server of worthy changes to |
| 56 | // our local state. It runs in its own goroutine. |
| 57 | func (c *Auto) updateRoutine() { |
| 58 | defer close(c.updateDone) |
| 59 | bo := backoff.NewBackoff("updateRoutine", c.logf, 30*time.Second) |
| 60 | |
| 61 | // lastUpdateGenInformed is the value of lastUpdateAt that we've successfully |
| 62 | // informed the server of. |
| 63 | var lastUpdateGenInformed updateGen |
| 64 | |
| 65 | for { |
| 66 | if !c.waitUnpause("updateRoutine") { |
| 67 | c.logf("updateRoutine: exiting") |
| 68 | return |
| 69 | } |
| 70 | c.mu.Lock() |
| 71 | gen := c.lastUpdateGen |
| 72 | ctx := c.mapCtx |
| 73 | needUpdate := gen > 0 && gen != lastUpdateGenInformed && c.loggedIn |
| 74 | c.mu.Unlock() |
| 75 | |
| 76 | if !needUpdate { |
| 77 | // Nothing to do, wait for a signal. |
| 78 | select { |
| 79 | case <-ctx.Done(): |
| 80 | continue |
| 81 | case <-c.updateCh: |
| 82 | continue |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | t0 := c.clock.Now() |
| 87 | err := c.direct.SendUpdate(ctx) |
| 88 | d := time.Since(t0).Round(time.Millisecond) |
| 89 | if err != nil { |
| 90 | if ctx.Err() == nil { |
| 91 | c.direct.logf("lite map update error after %v: %v", d, err) |
| 92 | } |
| 93 | bo.BackOff(ctx, err) |
| 94 | continue |
| 95 | } |
| 96 | bo.Reset() |
| 97 | c.direct.logf("[v1] successful lite map update in %v", d) |
| 98 | |
| 99 | lastUpdateGenInformed = gen |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | // atomicGen is an atomic int64 generator. It is used to generate monotonically |
| 104 | // increasing numbers for updateGen. |
no test coverage detected