Question

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())
Était-ce utile?

La solution

For example,

package main

import "fmt"

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

Output:

4
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top