Buffered Channels
- 公開日:
- 更新日:
- 文字数:222文字
package main import "fmt" func main(){ ch := make(chan int, 2) ch <- 100 fmt.Println(len(ch)) ch <- 200 fmt.Println(len(ch)) close(ch) for c := range ch{ fmt.Println(c) } }
package main import "fmt" func main(){ ch := make(chan int, 2) ch <- 100 fmt.Println(len(ch)) ch <- 200 fmt.Println(len(ch)) close(ch) for c := range ch{ fmt.Println(c) } }