go-learn/goroutines.go

29 lines
380 B
Go
Raw Normal View History

2021-03-10 09:13:54 +00:00
package main
import (
"fmt"
"time"
)
func f(from string) {
for i := 0; i < 3; i++ {
fmt.Println(from, ":", i)
}
}
func main() {
f("direct FIRST")
go f("goroutine one SECOND")
go f("goroutine two THIRD")
go func(msg string) {
fmt.Println(msg + " <IN MAIN> ")
go f("goroutine three <IN MAIN> FOURTH")
}("going")
time.Sleep(time.Second)
fmt.Println("done")
}