Frage

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())
War es hilfreich?

Lösung

For example,

package main

import "fmt"

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

Output:

4
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top