gobuch/concurrency/first-go-routine-mit-channel/main.go

25 lines
318 B
Go
Raw Normal View History

2020-08-21 04:26:40 +00:00
package main
import (
"fmt"
"math/rand"
"time"
)
var c chan string
func printOut() {
for i := 1; ; i++ {
c <- fmt.Sprintf("Print %v", i)
time.Sleep(time.Duration(rand.Intn(500)) * time.Millisecond)
}
}
func main() {
c = make(chan string)
go printOut()
for i := 0; i < 10; i++ {
fmt.Println(<-c)
}
}