知识卡片
任务承载Future
Future 是可被轮询的计算状态,任务是运行时管理这种状态的调度单位。join! 把多个 Future 组合进同一个任务。spawn 可独立调度,通常返回用于观察完成的句柄。直接 await 会使当前分支在子 Future 完成前停在原处。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Chapter 2. Basic Async Rust 从操作步骤到执行任务 · 查看原书依据
When we pass our futures into the tokio::join macro, all the async expressions are evaluated concurrently in the same task. The join macro does not create tasks; it merely enables multiple futures to be executed concurrently within the task. For instance, we can spawn a task with the following code:
参考来源
- 位置:《Async Rust Unleashing the Power of Fearless Concurrency (Maxwell Flitton, Caroline Morton)》第02章《Chapter 2. Basic Async Rust》,从操作步骤到执行任务(来源项目 book-source,extracted/Async Rust Unleashing the Power of Fearless Concurrency (Maxwell Flitton, Caroline Morton)/_epub-src/OEBPS/ch02.html#id10)
- 结论依据:咖啡与吐司例子区分同任务 join! 和 spawn 出的独立任务。
- 原始内容:When we pass our futures into the tokio::join macro, all the async expressions are evaluated concurrently in the same task. The join macro does not create tasks; it merely enables multiple futures to be executed concurrently within the task. For instance, we can spawn a task with the following code: