package main
import (
"fmt"
"time"
)
func main() {
c1 := make(chan string, 1)
go func() {
time.Sleep(time.Second * 2)
c1 <- "result 1"
}()
select {
case res := <-c1:
fmt.Println(res)
//延时器,当上个case超时执行这个case
case <-time.After(time.Second * 1):
fmt.Println("timeout 1")
}
c2 := make(chan string, 1)
go func() {
time.Sleep(time.Second * 2)
c2 <- "result 2"
}()
select {
case res := <-c2:
fmt.Println(res)
case <-time.After(time.Second * 3):
fmt.Println("timeout 2")
}
}
相关文章
- PostgreSQL 中如何处理数据的并发读写和锁等待超时?
- go语言处理特定格式的时间 例如打印出来2024-07-12 12:22:22 -2024-07-12 12:52:22
- go语言使用go-sciter创建桌面应用(三) 事件处理,函数与方法定义,go与tiscript之间相互调用
- 【轮询】【ajax】【js】【spring boot】ajax超时请求:前端轮询处理超时请求解决方案 + spring boot服务设置接口超时时间的设置
- 【webrtc】MessageHandler 6: 基于线程的消息处理:StunRequest实现包发送和超时重传
- Python 连接 Oracle 数据库加入超时处理机制-1. 示例代码
- spannerlib优雅的go异常处理
- 95.Go设计优雅的错误处理(带堆栈信息)
- Selenium最全超时等待问题的处理方案
- MySQL数据库连接超时(wait_timeout)问题的处理