Sobes.tech
Junior — Middle

At what stage of the lifecycle is a goroutine launched in Go?

sobes.tech AI

Answer from AI

A goroutine in Go is launched at the moment the go keyword is called before a function or method. This occurs during program execution when the control flow reaches this statement. For example:

func sayHello() {
    fmt.Println("Hello")
}

func main() {
    go sayHello() // a goroutine is launched here
    // the main function can continue to work
}

Thus, the goroutine starts dynamically during execution, not at compile time or initialization.

At what stage of the lifecycle is a goroutine… - sobes.tech