package main
import (
"fmt"
"sync"
)
var wg sync.WaitGroup
func printer(ch chan int) {
for i := range ch {
fmt.Println("Receive ",i)
}
wg.Done()
}
func main() {
c := make(chan int)
go printer(c)
wg.Add(1)
for i := 1;i<= 10; i ++ {
c <- i
}
close(c)
wg.Wait()
}
简单的go程序
猜你喜欢
转载自blog.csdn.net/wymyimeng/article/details/82584548
周排行