I'm making a function call_data()
, it will return a future. In the main function, I use tokio task to call call_data()
forever each 60 seconds. Some time, the call_data()
.await is a Error, so there is a panic! and stop the program. I try let a = call_data("name", "table").await;
, then use match
, if Ok
, future is excuted, if Error
, continue. However, that is not work, if there is panic!, still throw the panic!. Do I have any ways to avoid the panic! for this program? Below is the code I do not using match!
async fn main() {
let forever = task::spawn(async {
let mut interval = interval(Duration::from_millis(60000));
println!("Start");
loop {
interval.tick().await;
call_data("name", "table").await;
}
});
forever.await;
}
async fn call_data(name:&str, table: &str){
data().unwrap();
}
This is the code I use match
async fn main() {
let forever = task::spawn(async {
let mut interval = interval(Duration::from_millis(60000));
println!("Start");
loop {
let a =call_data("BTC-USD", "test3").await;
match a{
Ok=>(),
Err=>continue,
}
}
});
forever.await;
}
async fn call_data(name:&str, table: &str){
data().unwrap();
}