nextTick computes the delay until the next epoch-aligned boundary for the given interval, plus a random jitter in [0, jitter). It returns the target boundary and the total delay from now.
(now time.Time, interval, jitter time.Duration)
| 197 | // for the given interval, plus a random jitter in [0, jitter). It |
| 198 | // returns the target boundary and the total delay from now. |
| 199 | func nextTick(now time.Time, interval, jitter time.Duration) (boundary time.Time, delay time.Duration) { |
| 200 | boundary = nextBoundary(now, interval) |
| 201 | delay = boundary.Sub(now) |
| 202 | if jitter > 0 { |
| 203 | //nolint:gosec // Jitter does not need cryptographic randomness. |
| 204 | delay += time.Duration(rand.Int63n(int64(jitter))) |
| 205 | } |
| 206 | return boundary, delay |
| 207 | } |
| 208 | |
| 209 | // nextBoundary returns the first multiple of interval (relative to |
| 210 | // epoch) that is strictly after t. |