知识卡片
Future装饰器保留契约
包装 Future 可以统计轮询、记录结果或提供观测,同时转发 Pending、Ready 及唤醒上下文。每次 poll 的计时与一次业务操作的总延迟含义不同。固定外层后投影内部时要维持内层地址稳定,Pin> 是书中给出的安全替代。关联 [[Pin保护自引用]]。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Chapter 9. Design Patterns 装饰器透明封装额外动作 · 查看原书依据
For this decorator, we are going to implement a logging trait, and our example is going to call a log function before we poll the inner future. Our logging trait takes the following form:
参考来源
- 位置:《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#id59)
- 结论依据:原书的 LoggingFuture 在 poll 前记录日志,再把同一个 Context 传给内层。
- 原始内容:For this decorator, we are going to implement a logging trait, and our example is going to call a log function before we poll the inner future. Our logging trait takes the following form: