I wrote this code, but when sending pings, the program cannot do anything else. How can I spawn another thread to do this work while I do something else in my program?
pub fn sending_ping(addr: Addr<MicroscopeClient>) -> Result<(), ()> {
info!("Pings started");
spawn(async move {
loop {
info!("Ping");
match addr.send(Ping {}).await {
Ok(_) => {
info!("Ping sended")
}
Err(e) => {
warn!("Ping error");
return;
}
}
std::thread::sleep(Duration::from_millis((4000) as u64));
}
});
return Ok(());
}