我的频道还剩多少容量?

有没有办法在 Go 中查看我的异步通道中剩余多少存储空间?


例如


a chan uint=make(chan bool, 5)

a<-true

fmt.Printf(a.capazity())


Cats萌萌
浏览 207回答 1
1回答

喵喔喔

例如,package mainimport "fmt"func main() {&nbsp; &nbsp; a := make(chan bool, 5)&nbsp; &nbsp; a <- true&nbsp; &nbsp; fmt.Println(cap(a) - len(a))}输出:4
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go