How best do I keep a long running Go program, running?

后端 未结 6 1995
半阙折子戏
半阙折子戏 2020-12-04 13:22

I\'ve a long running server written in Go. Main fires off several goroutines where the logic of the program executes. After that main does nothing useful. Once main exits

6条回答
  •  鱼传尺愫
    2020-12-04 13:36

    Block forever. For example,

    package main
    
    import (
        "fmt"
        "time"
    )
    
    func main() {
        go forever()
        select {} // block forever
    }
    
    func forever() {
        for {
            fmt.Printf("%v+\n", time.Now())
            time.Sleep(time.Second)
        }
    }
    

提交回复
热议问题