package main
import (
"fmt"
"time"
)
var timeoutchan chan bool
func init () {
timeoutchan = make(chan bool ,1)
}
func main() {
f13_1()
// 通过睡眠模拟超时
time.Sleep(time.Second * 3)
f13_2()
time.Sleep(time.Second * 5)
}
func f13_1(){
go func () {
for {
<- time.After(time.Second*2)
select {
case <- timeoutchan:
fmt.Println("success...")
return
default:
fmt.Println("timeout...")
// TODO 做超时处理逻辑
return
}
}
}()
}
func f13_2() {
timeoutchan <- true
}
分类: time时间
0 条评论