1
0
forked from ROMEO/nexosim

Finalize the Context and BuildContext API

The API style is now more uniform: both are passed by mutable ref, and
only expose accessors. Additionally, the methods that were initially
accessed through the scheduler field are now directly implemented on
`Context`.
This commit is contained in:
Serge Barral
2024-11-15 16:00:18 +01:00
parent b1896dbde9
commit f4686af49a
21 changed files with 939 additions and 1054 deletions

View File

@ -15,14 +15,8 @@ fn model_schedule_event(num_threads: usize) {
output: Output<()>,
}
impl TestModel {
fn trigger(&mut self, _: (), context: &Context<Self>) {
context
.scheduler
.schedule_event(
context.scheduler.time() + Duration::from_secs(2),
Self::action,
(),
)
fn trigger(&mut self, _: (), cx: &mut Context<Self>) {
cx.schedule_event(Duration::from_secs(2), Self::action, ())
.unwrap();
}
async fn action(&mut self) {
@ -59,22 +53,11 @@ fn model_cancel_future_keyed_event(num_threads: usize) {
key: Option<ActionKey>,
}
impl TestModel {
fn trigger(&mut self, _: (), context: &Context<Self>) {
context
.scheduler
.schedule_event(
context.scheduler.time() + Duration::from_secs(1),
Self::action1,
(),
)
fn trigger(&mut self, _: (), cx: &mut Context<Self>) {
cx.schedule_event(Duration::from_secs(1), Self::action1, ())
.unwrap();
self.key = context
.scheduler
.schedule_keyed_event(
context.scheduler.time() + Duration::from_secs(2),
Self::action2,
(),
)
self.key = cx
.schedule_keyed_event(Duration::from_secs(2), Self::action2, ())
.ok();
}
async fn action1(&mut self) {
@ -117,22 +100,11 @@ fn model_cancel_same_time_keyed_event(num_threads: usize) {
key: Option<ActionKey>,
}
impl TestModel {
fn trigger(&mut self, _: (), context: &Context<Self>) {
context
.scheduler
.schedule_event(
context.scheduler.time() + Duration::from_secs(2),
Self::action1,
(),
)
fn trigger(&mut self, _: (), cx: &mut Context<Self>) {
cx.schedule_event(Duration::from_secs(2), Self::action1, ())
.unwrap();
self.key = context
.scheduler
.schedule_keyed_event(
context.scheduler.time() + Duration::from_secs(2),
Self::action2,
(),
)
self.key = cx
.schedule_keyed_event(Duration::from_secs(2), Self::action2, ())
.ok();
}
async fn action1(&mut self) {
@ -174,16 +146,14 @@ fn model_schedule_periodic_event(num_threads: usize) {
output: Output<i32>,
}
impl TestModel {
fn trigger(&mut self, _: (), context: &Context<Self>) {
context
.scheduler
.schedule_periodic_event(
context.scheduler.time() + Duration::from_secs(2),
Duration::from_secs(3),
Self::action,
42,
)
.unwrap();
fn trigger(&mut self, _: (), cx: &mut Context<Self>) {
cx.schedule_periodic_event(
Duration::from_secs(2),
Duration::from_secs(3),
Self::action,
42,
)
.unwrap();
}
async fn action(&mut self, payload: i32) {
self.output.send(payload).await;
@ -225,11 +195,10 @@ fn model_cancel_periodic_event(num_threads: usize) {
key: Option<ActionKey>,
}
impl TestModel {
fn trigger(&mut self, _: (), context: &Context<Self>) {
self.key = context
.scheduler
fn trigger(&mut self, _: (), cx: &mut Context<Self>) {
self.key = cx
.schedule_keyed_periodic_event(
context.scheduler.time() + Duration::from_secs(2),
Duration::from_secs(2),
Duration::from_secs(3),
Self::action,
(),