The only way to do this is to create a function around it. In your example, this is how you do it.
fmt.Println("We are doing something") //line below is my question go func() { for i := 1; i < 10; i ++ { fmt.Println("stuff running in background") } }() // life goes on fmt.Println("c'est la vie")
Note the actual function call at the end }()
. Otherwise, the compiler will complain to you.
source share