Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我找不到在 golang 中创建一块缓冲通道的方法。我知道如何创建如下给出的无缓冲通道切片
type ch chan int channels := make([]ch,5)
该语句channels := make([]ch,5)只是分配容器(长度为 5 的通道切片)。除此之外,您必须单独初始化每个通道,这是您将它们声明为缓冲而不是无缓冲的时候。所以扩展你的例子只是这样做:
channels := make([]ch,5)
for i, _ := range channels { channels[i] = make(chan int, BufferSize) }