Let's say I have something like this,
async fn do_update() {
// here we store it.
let task = task::spawn(async {
let duration = Duration::from_millis(10);
let mut stream = tokio::time::interval(duration);
stream.tick().await;
loop {
println!("Foo");
stream.tick().await;
}
});
// and here we await it.
task.await;
}
If I call that, like do_update().await the loop runs forever. Which is what I want. But I don't want it to be the only thing that runs. I just want it to block termination until the task is resolved.
I want an event to run every 5 seconds without blocking the rest of the program. This works exactly as I want, if I put it at the end of the program. It seems that this was once done with shutdown_on_idle, but the solution now offered isn't valid to me for the same reason as this comment,
I cannot implement it like that because I spawn inside of another task.
In a system where tasks spawn tasks, how can I be sure that the executable is only shut down when there are no more tasks running?