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,
}
...

  

转载于:https://www.cnblogs.com/LittleLee/p/9387804.html

你可能感兴趣的:(golang数据结构之chan篇)