其他分享
首页 > 其他分享> > go routine chan用法

go routine chan用法

作者:互联网

点击查看代码
package main

import (
	"fmt"
	"time"
)

func write(ch chan int) {
	for i := 0; i < 100; i++ {
		ch <- i
		fmt.Println("Put data:", i)
	}
}

func read(ch chan int) {
	for {
		fmt.Println("Read data:",<- ch)
	}
}

func main() {
	intChan := make(chan int, 10)
	go write(intChan)
	go read(intChan)
	time.Sleep(10 * time.Second)
}

标签:ch,package,int,time,chan,write,routine,go
来源: https://www.cnblogs.com/heris/p/15967596.html