golang数据结构之chan篇
package main
import (
"time"
"github.com/sanity-io/litter"
)
func main() {
var sliceChan = make(chan []int)
go func(c chan []int) {
for {
select {
case <-c:
litter.Dump(<-c)
default:
}
}
}(sliceChan)
go func() {
ticker := time.NewTicker(time.Second)
for {
<-ticker.C
sliceChan <- []int{1, 2, 3, 4}
}
}()
select {}
}
output:
[]int{
1,
2,
3,
4,
}
[]int{
1,
2,
3,
4,
}
[]int{
1,
2,
3,
4,
}
...

浙公网安备 33010602011771号