| 1 | package chronos |
| 2 | |
| 3 | import "time" |
| 4 | |
| 5 | // Schedule computes fire times. It is the single scheduling seam: it |
| 6 | // never sleeps and has no side effects. |
| 7 | type Schedule interface { |
| 8 | // Next returns the next fire time strictly after the given time, or |
| 9 | // the zero [time.Time] to mean "no further runs". The argument is |
| 10 | // the anchor; for a recurring schedule it is typically the time of |
| 11 | // the previous fire (or loop start for the first call). |
| 12 | Next(after time.Time) time.Time |
| 13 | } |
| 14 | |
| 15 | // everySchedule fires at a fixed [Span] past the anchor. It is |
| 16 | // stateless: each call is a single O(1) hop of after+span. |
| 17 | // |
| 18 | // It assumes a non-zero span; with a zero span Next would return after |
| 19 | // unchanged and violate the strictly-after contract. Constructors in |
| 20 | // later phases guard against an empty span, so this type may assume it. |
| 21 | type everySchedule struct { |
| 22 | span Span |
| 23 | } |
| 24 | |
| 25 | // Next returns after advanced by one span. |
| 26 | func (s everySchedule) Next(after time.Time) time.Time { |
| 27 | return s.span.addTo(after) |
| 28 | } |
| 29 | |