pub struct ScheduledSplit { /* private fields */ }Expand description
Divides one invocation’s ScheduledLimits across its modules, in
order, with every module’s unspent share rolling forward to the ones
after it.
The split is even by construction, not by outcome: module n of m
gets the wall time that is left divided by the modules still to run, and
the subrequests still left divided the same way (rounded up). The
invariant is on spend, not on the shares: shares overlap, because an
unspent share rolls forward and is granted again to the modules after
it, but every subrequest a module actually spends is subtracted from the
pool at settle — so cumulative spend never
passes the limit. A module that spends nothing simply leaves its share
in the pool for the next module.
Implementations§
Source§impl ScheduledSplit
impl ScheduledSplit
Sourcepub fn new(limits: ScheduledLimits, now: OffsetDateTime, modules: usize) -> Self
pub fn new(limits: ScheduledLimits, now: OffsetDateTime, modules: usize) -> Self
A split of limits across modules modules, starting at now.
now is read only when limits bounds wall time.
Sourcepub fn next(&mut self, now: OffsetDateTime) -> ScheduledBudget
pub fn next(&mut self, now: OffsetDateTime) -> ScheduledBudget
The budget for the next module: the time left divided by the modules still to run, and the subrequests left divided the same way (rounded up, so a share never names more steps than the pool holds, and the last module is left with at least what remains). Called once per module, in order.
Sourcepub fn settle(&mut self, budget: &ScheduledBudget)
pub fn settle(&mut self, budget: &ScheduledBudget)
Accounts for the module that just ran: its unspent subrequests roll
back into the pool for the modules still to come, and one fewer
module is waiting. Unspent wall time needs no accounting — the next
next recomputes it from the clock.