【发布时间】:2020-07-03 21:08:15
【问题描述】:
我有一个如下所示的主要功能:
func main() {
go SyncRealTime()
go SyncStale()
}
这两个功能都应该无限期地继续下去。我想main 到:
- 只要两个 Goroutine 都在运行,就不会终止。
- 如果任一 Goroutine 终止(即错误),则终止
在 Go 中这样做的惯用方式是什么?
【问题讨论】:
-
来自go spec
Program execution begins by initializing the main package and then invoking the function main. When that function invocation returns, the program exits. It does not wait for other (non-main) goroutines to complete.
标签: go