class documentation

class RecurrenceRule(Protocol[WhenT, StepsT]): (source)

View In Hierarchy

A RecurrenceRule is a callable that takes a reference time and a current time, and computes series of steps between the current recurrence and a new reference time for the next call.

Depending on the application, StepsT type can either be an integer (i.e.: a count of the number of steps that have passed between the reference time and the current time) or a collection of specific previous step timestamps, usually a collection of WhenT.

Method __call__ Given a reference time and a current time, compute the steps between the calls and the next reference time.
def __call__(self, reference: WhenT, current: WhenT) -> tuple[StepsT, WhenT]: (source)

Given a reference time and a current time, compute the steps between the calls and the next reference time.

Parameters
reference:WhenTthe time at which the current invocation was scheduled to occur; i.e. the time that the call was computed to have been called.
current:WhenTthe time at which the current invocation actually occurred; i.e. the time that the event loop got around to actually calling the function.
Returns
tuple[StepsT, WhenT]

a 2-tuple of:

  1. steps; the recurrences that were expected to have occurred between reference and the current time. So for example, for a RecurrenceRule representing a once-every-5-seconds recurrence, if your reference time were 1.0 and your current time were 15.0, then your step count should be 2, since recurrences should have occurred at 6.0 and 11.0. Alternately, for a RecurrenceRule[float, list[float]] with the same scheduled times, steps will be [6.0, 11.0].
  2. next reference time; time at which the next recurrence should occur. In our previous example, where our reference time was 1.0 and current time was 15.0, the next desired time should be 16.0, since that's the next 5-second recurrence after 11.0.
Note
The delta between the reference time and the current time will often be quite small. If a system is running actively and is not overloaded, then this delta will be close to zero. However, there are cases (some examples: a laptop goes to sleep, then wakes up hours later; a program schedules a call in a database and is not run for several weeks) when this delta can be very large.