In this video, we are going to be looking at goroutines in Go and what they are used for.
Overview
package main
import (
"fmt"
"time"
)
func HelloWorld(name string) {
time.Sleep(1 * time.Second)
fmt.Printf("hello: %s\n", name)
}
func main() {
go HelloWorld("Elliot")
fmt.Println("I should be printed first")
time.Sleep(2 * time.Second)
}
Output
$ go run main.go
I should be printed first
hello: Elliot