知识卡片
异步语法生成状态机
async 函数把跨等待点仍需要的变量保存在它生成的 Future 中。poll 可以用状态确定从哪个阶段继续。使用具体类型时编译器可静态分发,装箱为 trait 对象时才引入相应间接调用和分配。参见 [[Future轮询状态]]。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
- · 高层锁与状态机
原书出处 · 1 处
- Chapter 2. Basic Async Rust 高层锁与状态机 · 查看原书依据
Rust opted for an alternative approach with the aim of optimizing runtime performance by using the Future trait, which uses polls. The runtime is responsible for managing when to call polls. It does not need to schedule callbacks and worry about working out what function to call, instead it can use polls to see if the future is completed. This is more efficient because futures
参考来源
- 位置:《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#id76)
- 结论依据:原书以回调为对照,解释保存局部变量并由轮询推进的状态机。
- 原始内容:Rust opted for an alternative approach with the aim of optimizing runtime performance by using the Future trait, which uses polls. The runtime is responsible for managing when to call polls. It does not need to schedule callbacks and worry about working out what function to call, instead it can use polls to see if the future is completed. This is more efficient because futures