知识卡片
同签名包装组合治理
Circuit、Effector等函数类型约定参数与结果,装饰函数接收原函数并返回同签名闭包,把熔断、去抖或重试附加在调用边界。相同签名使包装可组合,但组合次序会改变语义,例如重试是在熔断内还是外。闭包共享的计数、缓存结果和定时器若被并发访问,仍必须同步。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Cloud Native Patterns · 查看原书依据
The similarity with the Circuit Breaker implementation is quite intentional: their compatibility makes them “chainable”, as demonstrated below. func myFunction func(ctx context.Context) (string, error) { /* ... */ } response, err := Breaker(Debounce(myFunction(ctx))) The function-first implementation of Debounce is very straight-forward compared to function-last because it only needs to track the last time it was
参考来源
- 位置:《Cloud Native Go》第04章《Cloud Native Patterns》(来源项目book-sources;源文件:extracted/Cloud Native Go (Matthew A. Titmus)/_epub-src/OEBPS/ch04.xhtml)
- 结论依据:Circuit、Effector等函数类型约定参数与结果,装饰函数接收原函数并返回同签名闭包,把熔断、去抖或重试附加在调用边界。原文相应定义、示例或限制为此结论提供依据;补充纠错与版本边界在正文就近标明。
- 原始内容:The similarity with the Circuit Breaker implementation is quite intentional: their compatibility makes them “chainable”, as demonstrated below. func myFunction func(ctx context.Context) (string, error) { /* ... */ } response, err := Breaker(Debounce(myFunction(ctx))) The function-first implementation of Debounce is very straight-forward compared to function-last because it only needs to track the last time it was