()
| 210 | } |
| 211 | |
| 212 | func (t *SlottedTicker) nextInterval() time.Duration { |
| 213 | slotIndex, totalSlots := t.sf() |
| 214 | |
| 215 | // Discover what time the last iteration started |
| 216 | lastStartTime := time.UnixMilli((time.Now().UnixMilli() / t.d.Milliseconds()) * t.d.Milliseconds()) |
| 217 | offset := time.Duration((float64(slotIndex) / float64(totalSlots)) * float64(t.d)) |
| 218 | // Lets offset the time of the iteration |
| 219 | lastStartTime = lastStartTime.Add(offset) |
| 220 | |
| 221 | // Keep adding the ticker duration until we pass time.now |
| 222 | for lastStartTime.Before(time.Now()) { |
| 223 | lastStartTime = lastStartTime.Add(t.d) |
| 224 | } |
| 225 | |
| 226 | slotSize := t.d / time.Duration(totalSlots) |
| 227 | return time.Until(lastStartTime) + PositiveJitter(slotSize, t.slotJitter) |
| 228 | } |
| 229 | |
| 230 | func ParseDurationMs(s string) (int64, error) { |
| 231 | if d, err := strconv.ParseFloat(s, 64); err == nil { |
no test coverage detected