Closed leon-thomm closed 11 months ago
(though much of my struggles might stem from my inexperience with the language :) so apologies if I'm over-engineering simple things, happy to learn more)
There is no real way to avoid the scheduler here, but you could save yourself a bit of typing by declaring a macro:
macro_rules! deferred_send {
($m:ty, $o:ident, $v:ty) => {{
async fn deferred(m: &mut $m, v: $v) {
let _ = m.$o.send(v).await;
}
deferred
}};
}
which you would use as follows:
scheduler.schedule_event(Duration::from_secs(1), deferred_send!(MyModel, output, Msg), msg).unwrap();
The macro works for requestor ports too, but obviously the reply is ignored.
If you come to the conclusion that the macro is worth adding to the library and/or have ideas how to improve it, please let me know.
Thanks, this works.
What is the best way to implement sending messages to an output with a delay? The docs suggest a self-scheduling mechanism, e.g.:
with a corresponding handler
but I feel this might get slightly tedious in complex models. Ideally, I would like to simply write
Any suggestions how I should do this?