【发布时间】:2019-06-27 14:57:10
【问题描述】:
有没有办法检测 go 例程在执行时是否被中断?我想要类似于 Java 中的 InterruptedException 的东西:https://docs.oracle.com/javase/8/docs/api/java/lang/InterruptedException.html
【问题讨论】:
-
goroutine 会如何被中断?
-
查看这个答案以讨论如何停止 goroutine stackoverflow.com/questions/6807590/how-to-stop-a-goroutine(更正链接)
-
这真的取决于你所说的“中断”是什么意思。你在 Java 中提到的中断不会在 Go 中发生。
标签: go concurrency interrupt goroutine interrupted-exception