A goroutine is a lightweight thread managed by the Go runtime.
go f(x)
func main() {
go func() {
time.Sleep(1 * time.Second) // heavy process
fmt.Println("goroutine completed")
}()
fmt.Println("next")
time.Sleep(2 * time.Second)
}
func main() {
go process()
fmt.Println("next")
time.Sleep(2 * time.Second)
}
func process() {
time.Sleep(1 * time.Second) // heavy process
fmt.Println("goroutine completed")
}