0106-Go-遍历通道
2023-09-27 14:23:45 时间
环境
- Time 2022-08-24
- Go 1.19
前言
说明
参考:https://gobyexample.com/range-over-channels
目标
使用 Go 语言的通道,并遍历通道。
示例
package main
import "fmt"
func main() {
queue := make(chan string, 2)
queue <- "one"
queue <- "two"
close(queue)
for elem := range queue {
fmt.Println(elem)
}
}
总结
使用 Go 语言的通道,并遍历通道。