質問

Is there a way to see how much storage is left in my asynchronous channel in Go?

For example

a chan uint=make(chan bool, 5)
a<-true
fmt.Printf(a.capazity())
役に立ちましたか?

解決

For example,

package main

import "fmt"

func main() {
    a := make(chan bool, 5)
    a <- true
    fmt.Println(cap(a) - len(a))
}

Output:

4
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top