関数を非同期実行することができる
async/awaitは、時間のかかる処理をするときに、処理が終わるまでのスレッドを別のタスクの処理に使うことができる機能を提供する
use futures::executor::block_on;
fn wait() -> f64 {
let mut x:f64 = 0.0;
for _ in 1..10000 {
for _ in 1..10000 {
x = x * 1.001;
}
}
x
}
async fn print_dot(){
println!(".");
}
async fn print_plus(){
plusfunc().await;
}
async fn print_minus() {
wait();
println!("-");
}
async fn plusfunc(){
wait();
println!("+");
}
async fn async_main() {
let f1 = print_plus();
let f2 = print_minus();
let f3 = print_dot();
println!("Hello");
futures::join!(f1, f2, f3);
}
fn main(){
block_on(async_main());
}