سؤال

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