len也可以作用于channel,代表现在channel缓冲区中还有多少数据没有读取.示例如下

    c:=make(chan int,20)
    fmt.Println("len:",len(c)) //0
    c<-1
    fmt.Println("len:",len(c)) //1
    c<-1
    fmt.Println("len:",len(c)) //2
    c<-1
    fmt.Println("len:",len(c)) //3
    <-c
    fmt.Println("len:",len(c)) //2

相关文章:

  • 2022-12-23
  • 2021-10-01
  • 2021-09-15
  • 2021-09-07
  • 2021-05-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-07-07
  • 2021-11-22
  • 2022-02-01
  • 2022-12-23
  • 2021-12-10
  • 2022-12-23
相关资源
相似解决方案