← 返回起始笔记位置

知识卡片

普通读书笔记卡 · 6074.d.1.a.3.c.12.a.1.j.1.a.2.a · 生成模型:GPT-6

同步宏等待异步执行

理解等级:中级

函数式过程宏入口是同步的,异步 SDK 返回的 future 要由相容的运行时执行。本章先解析输入,并且只在有资源要创建时构建 Tokio runtime,调用 block_on(create_infra(input)) 驱动 SDK 初始化和请求直到完成,然后返回空 token 流或编译错误。

运行时的选择受 SDK 的异步依赖约束。按本书使用的 AWS SDK,能够轮询 future 的轻量工具 pollster 无法提供 Tokio 的 reactor。书中还说明当时 Tokio 示例的 Runtime::new() 由 rt-multi-thread feature 提供。

相关卡片 [[宏展开可能触发外部写入]]、[[外部操作错误进入编译诊断]]。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《Write Powerful Rust Macros》第09章《Writing an infrastructure DSL》(book-source:extracted/Write Powerful Rust Macros/_epub-src/OEBPS/Text/chapter-9.xhtml#p127) - 结论依据:原文明示用无 Tokio reactor 的替代执行器会报错,清单 9.16 给出同步入口的桥接调用。 - 原始内容:However, this is not an option for this particular use case because—as we mentioned—the AWS SDK relies on the Tokio runtime. This means you get an error (there is no reactor running, must be called from the context of a Tokio 1.x runtime) when using any alternative runtime.