知识卡片

普通读书笔记卡 · 4545.g.3.d.1

上下文沿派生树传播取消

理解等级:中级

Context传递请求的截止时间、取消信号和请求范围数据。下游持有同一上下文或其派生值时,可在Done关闭后协作退出;取消子上下文不反向取消父上下文。取消只是信号,工作代码必须观察它,不会强制中止任意函数。WithTimeout返回上下文与cancel,使用者应负责及时调用cancel释放关联资源。

这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Cloud Native Patterns · 查看原书依据

      A Context is used by passing it directly to a new service request upon its creation, and may then be passed to any sub-requests. What makes this useful is that when the Context canceled, all functions holding it (or a derived Context; more on this below) will receive the signal, allowing them to coordinate their

    参考来源

    - 位置:《Cloud Native Go》第04章《Cloud Native Patterns》(来源项目book-sources;源文件:extracted/Cloud Native Go (Matthew A. Titmus)/_epub-src/OEBPS/ch04.xhtml) - 结论依据:Context传递请求的截止时间、取消信号和请求范围数据。原文相应定义、示例或限制为此结论提供依据;补充纠错与版本边界在正文就近标明。 - 原始内容:A Context is used by passing it directly to a new service request upon its creation, and may then be passed to any sub-requests. What makes this useful is that when the Context canceled, all functions holding it (or a derived Context; more on this below) will receive the signal, allowing them to coordinate their