商君

导航

Go Example--通道遍历

package main

import (
	"fmt"
)

func main() {
	queue := make(chan string, 2)
	queue <- "one"
	queue <- "two"
	close(queue)

	//for range chan 知道通道关闭
	for elem := range queue {
		fmt.Println(elem)
	}
}

posted on 2018-10-19 16:27  漫步者01  阅读(125)  评论(0编辑  收藏  举报