Here's a minimal example of an issue I'm having:
#[tokio::main]
async fn main() {
tokio::spawn(async move {
let mut counter = 0;
loop {
std::thread::sleep(std::time::Duration::from_secs_f32(1.));
counter += 1;
if counter <= 5 {
println!("schedule {counter}");
tokio::spawn(async move {
println!("execute {counter}");
});
} else {
println!("skip {counter}");
}
}
}).await.unwrap();
}
output is as follows:
schedule 1
schedule 2
execute 1
schedule 3
execute 2
schedule 4
execute 3
schedule 5
execute 4
skip 6
skip 7
skip 8
skip 9
skip 10
...
In this example, "execute 5" is never printed. Why?