Goroutines
Lightweight concurrency and threading
package main
import (
"fmt"
"time"
)
func main() {
// run the say function in a goroutine
go say("world")
say("hello")
}
// intentionally delay the say function, so simulate a long
// running proccess
func say(s string) {
for i := 0; i < 5; i++ {
time.Sleep(100 * time.Millisecond)
fmt.Println(s)
}
}Last updated