Closed leon-thomm closed 1 year ago
A workaround that does not involve boxing is mentioned in the docs, would that work for you? In your case I guess it would look something like:
fn on_fetch<'a>(
&'a mut self,
_: (),
scheduler: &'a Scheduler<Self>
) -> impl Future<Output=()> + Send + 'a {
async move {
let b = self.blackbox();
println!("fetching!\n{}", if b {"success"} else {"failure, retrying in 1s"});
if b { scheduler.schedule_in(Duration::from_secs(5), Self::on_fetch, ()); }
else { scheduler.schedule_in(Duration::from_secs(1), Self::on_fetch, ()); }
}
}
Oh, I remember I read that once but then didn't find it again, my bad! Not the prettiest thing, but for my purposes this is what I need. Thanks!
To be honest it took me a minute to find again where that piece of documentation was, I should probably move it to the top level. True, the syntax is a bit noisy, I'm hopeful rustc will remove this pain point in a not too far future...
I'd like to self-schedule an input from within that same input. Something like this:
Rust doesn't allow for direct recursion in
async
functions, so this will give a compiler error. Generally, on workaround is to return aBoxFuture
(instead of aFuture
).This messes up the code quite a bit, so I was looking for a nicer way to do this. The only alternative I found is to create a dedicated loopback output
But this is not any better, it requires the simulator to connect the output correctly, and assumes that the output is not connected to anything else.
Is there a better way to do this with asynchronix?