package main
import (
"fmt"
"time"
)
func main() {
ch1 := make(chan int)
quit := make(chan bool)
go func() {
for{
select {
case <-ch1:
fmt.Printf("读取到数据\n")
break
case <-time.After(3*time.Second):
fmt.Printf("超时拉\n")
quit<-true
goto lable
}
fmt.Printf("=============\n")
}
lable:
}()
for i:=0;i<2;i++{
ch1<-i
time.Sleep(2*time.Second)
}
<-quit
fmt.Printf("完毕")
}
来源:CSDN
作者:LH专属荷包
链接:https://blog.csdn.net/weixin_42067668/article/details/103483617