知识卡片
同步入口分离提交与等待
迁移同步代码时,可以先提供提交和取结果两个入口,将 async 类型和运行时隔离在模块内。结果是否只消费一次、等待能否超时、未领取的句柄何时回收都要写明。异步工作线程内应选异步等待接口,避免嵌套阻塞运行时。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Chapter 9. Design Patterns 同步提交与阻塞取结果 · 查看原书依据
As Figure 9-1 lays out, we send an async task to the runtime, put the handle in a map for those async tasks, and return a key that corresponds to the handle in the map. The developer using the module calls a normal blocking function and receives a unique ID back. The task is being progressed in the async runtime, and the developer can write
参考来源
- 位置:《Async Rust Unleashing the Power of Fearless Concurrency (Maxwell Flitton, Caroline Morton)》第09章《Chapter 9. Design Patterns》,同步提交与阻塞取结果(来源项目 book-source,extracted/Async Rust Unleashing the Power of Fearless Concurrency (Maxwell Flitton, Caroline Morton)/_epub-src/OEBPS/ch09.html#buildIsolatedModule)
- 结论依据:书中用 ID 代表可延后等待的句柄,在同步接口背后独立推进异步工作。
- 原始内容:As Figure 9-1 lays out, we send an async task to the runtime, put the handle in a map for those async tasks, and return a key that corresponds to the handle in the map. The developer using the module calls a normal blocking function and receives a unique ID back. The task is being progressed in the async runtime, and the developer can write