【发布时间】:2020-06-26 13:31:12
【问题描述】:
给定一个异步函数及其对应的未来,让我们说:
async fn foo() -> Result<i32, &'static str> {
// ...
}
let my_future = foo();
仅使用 .await 等待它与使用 tokio::spawn().await 有什么区别?
// like this...
let result1 = my_future.await;
// ... and like this
let result2 = tokio::spawn(my_future).await;
【问题讨论】:
-
my_future.await需要先完成,然后立即出现的任何代码才会运行。生成新任务将继续当前任务,同时在新任务中运行未来。
标签: rust rust-tokio