内容简介:demo 如下:每天坚持学习1小时Go语言,大家加油,我是彬哥,下期见!如果文章中不同观点、意见请文章下留言或者关注下方订阅号反馈!
demo 如下:
package main import ( "fmt" "net/http" "time" ) var chandata chan map[int]int func init() { chandata = make(chan map[int]int) go TTimerAddData() go TTimeGetData() } // 压入数据测试 func TTimerAddData() { vcount := 1 keycount := 10000 for { select { case <-time.After(time.Second * 10): { data := make(map[int]int) data[keycount] = vcount vcount++ keycount++ chandata <- data } } } } // 获取数据测试 func TTimeGetData() { for { select { case <-time.After(time.Second * 1): { } case i := <-chandata: { for v := range i { fmt.Println("-----------------i", i) fmt.Println("-----------------v", v) fmt.Println("-----------------vi", i[v]) } } } } } func main() { strport := "8892" // GM 系统操作 -- 修改金币等操作 http.HandleFunc("/GolangLtdGM", IndexHandlerGM) http.ListenAndServe(":"+strport, nil) return }
输出结果
每天坚持学习1小时 Go 语言,大家加油,我是彬哥,下期见!如果文章中不同观点、意见请文章下留言或者关注下方订阅号反馈!
社区交流群:221273219
Golang语言社区论坛 :
LollipopGo游戏服务器地址:
https://github.com/Golangltd/LollipopGo
社区视频课程课件GIT地址:
https://github.com/Golangltd/codeclassGolang语言社区
以上所述就是小编给大家介绍的《Go语言多任务超时处理-channel实现demo》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- redigo设置超时时间
- 深入理解 JDBC 的超时
- [golang]一定要设置超时
- 超时与重试机制(一)
- MongoDB 查询超时异常 SocketTimeoutException
- Go并发调用的超时处理
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
The Everything Store
Brad Stone / Little, Brown and Company / 2013-10-22 / USD 28.00
The definitive story of Amazon.com, one of the most successful companies in the world, and of its driven, brilliant founder, Jeff Bezos. Amazon.com started off delivering books through the mail. Bu......一起来看看 《The Everything Store》 这本书的介绍吧!