#Async closure not working properly with smol?
15 messages · Page 1 of 1 (latest)
it gives the same error
My apologies, I made a typo
oh wait without the closure oki lemme see
it compiles! but it seems that the second spawn is definitely delayed from the first
Yes, since you're awaiting them in series
oh i see
how do i start them at the same time
I believe futures::join!() is the tool for this:
use std::time::{Duration, Instant};
fn main() -> anyhow::Result<()> {
smol::block_on(async {
let task1 = async {
for x in 0..5 {
smol::Timer::after(Duration::from_secs(1)).await;
println!("{}", x + 1);
}
};
let task2 = async {
smol::Timer::at(Instant::now() + Duration::from_secs(5)).await;
println!("5 seconds have passed!");
smol::Timer::at(Instant::now() + Duration::from_secs(10)).await;
println!("10 seconds have passed!");
};
futures::join!(task1, task2);
Ok(())
})
}
I'm honestly not quite sure what smol::spawn() is supposed to do
probably the same thing as tokio::spawn?
its for creating threads :P
yes
Ah, so an async thread::spawn(), that makes sense
But futures::join!() should still be the ticket here
it works 