知识卡片
异步重叠等待
假设四个独立请求都需要等待约同样的时间,并发轮询允许它们都开始等待,完成时间就更接近最慢的请求。这个收益依赖实际发生的等待。若任务在可运行期间一直做计算,单线程仍只能依次执行这些计算。创建 Future 先构造状态,顺序 await 仍会保留依赖顺序。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Chapter 1. Introduction to Async 异步如何利用等待时间 · 查看原书依据
Here we are using tokio::join!, a macro provided by Tokio. This macro enables multiple tasks to run concurrently. Unlike the previous example, where requests were awaited one after another, this approach allows them to progress simultaneously. As expected, running this code gives us a duration time of 137 ms. That’s a 4.7 times increase in the speed of our program without increasing the number of
参考来源
- 位置:《Async Rust Unleashing the Power of Fearless Concurrency (Maxwell Flitton, Caroline Morton)》第01章《Chapter 1. Introduction to Async》,异步如何利用等待时间(来源项目 book-source,extracted/Async Rust Unleashing the Power of Fearless Concurrency (Maxwell Flitton, Caroline Morton)/_epub-src/OEBPS/ch01.html#id4)
- 结论依据:原书将四次顺序等待与 join! 重叠等待比较,说明独立 I/O 的等待时间可重叠。
- 原始内容:Here we are using tokio::join!, a macro provided by Tokio. This macro enables multiple tasks to run concurrently. Unlike the previous example, where requests were awaited one after another, this approach allows them to progress simultaneously. As expected, running this code gives us a duration time of 137 ms. That’s a 4.7 times increase in the speed of our program without increasing the number of