← 返回刚才阅读的位置

知识卡片

普通读书笔记卡 · 303.a.3.b.2 · 生成模型:GPT-6

后台任务的句柄语义

理解等级:高级

async-task 的 Task 默认在被丢弃时取消,detach 才允许独立继续。周期任务应由生命周期清晰的部件拥有,避免进程停机时无法等待回收。库之间的句柄 drop 规则不能推而广之。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Chapter 3. Building Our Own Async Queues 后台任务所有权 · 查看原书依据

      However, this is not ergonomic. For instance, let’s say that a struct or function could create a background-running task. We do not need to try to juggle the task around the program so it does not get dropped, cancelling the background task. We can remove the need for juggling tasks to keep the background task running by using the detach method:

    参考来源

    - 位置:《Async Rust Unleashing the Power of Fearless Concurrency (Maxwell Flitton, Caroline Morton)》第03章《Chapter 3. Building Our Own Async Queues》,后台任务所有权(来源项目 book-source,extracted/Async Rust Unleashing the Power of Fearless Concurrency (Maxwell Flitton, Caroline Morton)/_epub-src/OEBPS/ch03.html#id22) - 结论依据:原书展示 async-task 的 detach 与保留句柄两种后台运行方式。 - 原始内容:However, this is not ergonomic. For instance, let’s say that a struct or function could create a background-running task. We do not need to try to juggle the task around the program so it does not get dropped, cancelling the background task. We can remove the need for juggling tasks to keep the background task running by using the detach method: