1
0
forked from ROMEO/nexosim

Make it possible to cancel current-time events

This is a pretty large patch that impacts the API.

Until now, it was not possible to cancel events that were scheduled for
the current simulation time slice, making it necessary for the user to
use complex workarounds (see former version of the espresso machine
example).

The new implementation makes this possible but the generation of a key
associated to an event has now a non-negligible cost (basicaly it
creates three references to an Arc). For this reason, the API now
defaults to NOT creating a key, and new methods were added for
situations when the event may need to be cancelled and a key is
necessary.

See the much simplified implementation of the espresso machine example
for a motivating case.
This commit is contained in:
Serge Barral
2023-07-19 19:01:37 +02:00
parent 045dea509c
commit f458377308
9 changed files with 535 additions and 199 deletions

View File

@ -174,7 +174,7 @@ impl Driver {
// Schedule the next pulse.
scheduler
.schedule_in(pulse_duration, Self::send_pulse, ())
.schedule_event_in(pulse_duration, Self::send_pulse, ())
.unwrap();
}
}
@ -224,7 +224,7 @@ fn main() {
assert!(position.next().is_none());
// Start the motor in 2s with a PPS of 10Hz.
simu.schedule_in(
simu.schedule_event_in(
Duration::from_secs(2),
Driver::pulse_rate,
10.0,