Book: Request for a 0.5 -> 1.0 migration example for drift free scheduling using `cx.scheduled`
prutschman opened this issue · comments
The 0.5 book shows an example of drift-free scheduling by access a context parameter scheduled
cx.schedule.foo(cx.scheduled + PERIOD.cycles()).unwrap();
The book goes on to say "Using Instant::now instead of scheduled would have resulted in drift / jitter."
In the 1.0 book, though, the migration just says "the requirement of having access to the context is dropped.". It appears to me, though, that calling task::spawn_after
is equivalent to basing the offset on now
rather than the scheduled time.
Is drift-free scheduling possible in 1.0?
Hi!
You are correct, that using task::spawn_after
is equivalent to scheduling "forward" with baseline from now
.
In 1.0 you have the option to also use task::spawn_at
, which expects a specific time instant, ie not derived from whatever "now" is. This allows for drift-free scheduling if those instances provided to task::spawn_at
do not shift around relative to each other.
E.g. (pseudo-code) foo::spawn_at(0), foo::spawn_at(n*100), ....
For further explanation see: the book: Monotonic & spawn_{at/after}
The current migration docs regarding this topic can be found here, if you find this lacking it would be greatly appreciated if you would like to provide such an example, I can assist with the details.