← 返回刚才阅读的位置

知识卡片

普通读书笔记卡 · 1538.c.3 · 生成模型:GPT-6

取消安全依赖进度

理解等级:高级

释放 Future 会销毁它持有的本地状态,但远端请求、已读走的字节或已经提交的写入可能保留。把可恢复进度保存在取消范围外、记录操作身份、或让提交和确认形成明确协议,才能安全地从等待点重试。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Chapter 2. Basic Async Rust 取消怎样影响业务结果 · 查看原书依据

      In our example, if the slow_task() is canceled due to the timeout, the task itself is simply stopped, and the timeout returns an error indicating the task didn’t complete in time. Since tokio::time::sleep is a cancel-safe operation, there’s no risk of resource leaks or inconsistent states. However, if the task involves more complex operations, such as network communication or file I/O, additional care might be

    参考来源

    - 位置:《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#id400) - 结论依据:超时后睡眠可以丢弃,原书对网络和文件交互另作提醒。 - 原始内容:In our example, if the slow_task() is canceled due to the timeout, the task itself is simply stopped, and the timeout returns an error indicating the task didn’t complete in time. Since tokio::time::sleep is a cancel-safe operation, there’s no risk of resource leaks or inconsistent states. However, if the task involves more complex operations, such as network communication or file I/O, additional care might be