package main
import (
"fmt"
"time"
)
func dataChanTest(data chan int){
tickTimer := time.NewTicker(5 * time.Second)
for{
select {
case a,_:=<-data:
fmt.Println(a)
case t:=<-tickTimer.C:
fmt.Println("Time Out ! "+t.String())
}
}
}
func main() {
var data = make(chan int,10)
go dataChanTest(data)
for i:=0;;i++{
data<-i
time.Sleep(time.Second * 3)
}
}
package main
import (
"fmt"
"time"
)
func dataChanTest(data chan int) {
for {
select {
case a, _ := <-data:
fmt.Println(a)
case t := <-time.After(5 * time.Second):
fmt.Println("Time Out ! " + t.String())
}
}
}
func main() {
var data = make(chan int, 10)
go dataChanTest(data)
for i := 0; ; i++ {
data <- i
time.Sleep(time.Second * 3)
}
}