小编Ale*_*aev的帖子

How to execute multiple async functions at once and get the results?

I have tried Tokio tasks, but there are no working examples to execute multiple tasks at once. What is wrong with this code?

fn main() {
    block_on(speak());
}

async fn speak() {
    let hold = vec![say(), greet()];
    let results = join_all(hold).await;
}

async fn say() {
    println!("hello");
}

async fn greet() {
    println!("world");
}
Run Code Online (Sandbox Code Playgroud)

here is the compiler output

error[E0308]: mismatched types
  --> sync\src\main.rs:14:27
   |
14 |     let hold = vec![say(),greet()];
   |                           ^^^^^^^ expected opaque type, found a different opaque …
Run Code Online (Sandbox Code Playgroud)

rust async-await rust-tokio

5
推荐指数
1
解决办法
1475
查看次数

标签 统计

async-await ×1

rust ×1

rust-tokio ×1