跨流程传递截止日期和取消信号

跨流程传递截止日期和取消信号

问题描述:

The golang context documentation says :

Package context defines the Context type, which carries deadlines, cancelation signals, and other request-scoped values across API boundaries and between processes.

I also read concrete examples of context, but I don't see any information on carring deadlines and cancellation signals across processes.

How does signals work across processes?

Are they reliable like, if service1 sends a cancel signal but it dies, and signal is lost, what happens now?

golang context 文档说: p>

包上下文定义了Context类型,该类型携带截止时间, 取消信号和其他跨请求范围的值 API边界 和进程之间。 p> blockquote>

我还阅读了具体的示例 关于上下文,但我没有看到有关流程 strong>中的截止日期和取消信号 code>的任何信息。 p>

信号如何在整个过程中发挥作用 流程? p>

它们是否可靠,例如,如果service1发送取消信号但它死亡,并且信号丢失,那么现在会发生什么? p> div>

Sorry to break your enthusiasm, but the context package cannot be used as-is for inter-process communication and signaling.

The wording here may be a little imperfect, as in the "context" of the context package documentation most people would think of "processes" as an OS process entity. But the word "process" has multiple meanings, and the more general "a set of activities that interact to achieve a result" meaning is used here (from Wikipedia: Process). To avoid ambiguity, "goroutines" or "a set of goroutines" would be more appropriate here, but within the same Go application.

Note that when the context package was first published as a separate, experimental package (not as part of the standard library), this blog post explained its background and uses: Go Concurrency Patterns: Context. The context haven't change since it was integrated into the standard library, and that blog post did not mention the word "process", not even once.