Mastering-Go-Second-Edition/ch09/create.go
2019-01-10 22:09:57 +02:00

23 lines
334 B
Go

package main
import (
"flag"
"fmt"
"time"
)
func main() {
n := flag.Int("n", 10, "Number of goroutines")
flag.Parse()
count := *n
fmt.Printf("Going to create %d goroutines.\n", count)
for i := 0; i < count; i++ {
go func(x int) {
fmt.Printf("%d ", x)
}(i)
}
time.Sleep(time.Second)
fmt.Println("\nExiting...")
}