I am new to Rust. I used to think async is a program that runs in child threads, but when I run my code, the block in my main thread affects the child threads. I don't know what the problem is, and I hope you can help me.
#[tokio::main]
async fn main() {
fil_logger::init();
let (tx,rx) = oneshot::channel();
let srv = servers::sc_servers("",rx);
for i in {1..10}{
println!("{}",i);
sleep(Duration::from_secs(1))
}
// signal::ctrl_c().await;
// tx.send("stop");
srv.await;
}
pub async fn sc_servers(addr: &str,rx:tokio::sync::oneshot::Receiver<&str>) {
// defining address for our service
let mut listen_addr: SocketAddr = "[::1]:50051".parse().unwrap();
if addr != "" {
listen_addr = addr.parse().unwrap()
}
/// 1.register server
let srv_reg = RegisterCenterServer::default();
println!("Scheduler Servers listening on {}", listen_addr);
Server::builder()
.add_service(RegisterServiceServer::new(srv_reg))
.serve_with_shutdown(listen_addr,rx.map(drop))
.await
.unwrap();
println!("sc here")
}
Get this result