Go语言多任务超时处理-channel实现demo

栏目: Go · 发布时间: 5年前

内容简介: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
}
Go语言多任务超时处理-channel实现demo

输出结果

每天坚持学习1小时 Go 语言,大家加油,我是彬哥,下期见!如果文章中不同观点、意见请文章下留言或者关注下方订阅号反馈!

社区交流群:221273219

Golang语言社区论坛 :

www.Golang.Ltd

LollipopGo游戏服务器地址:

https://github.com/Golangltd/LollipopGo

社区视频课程课件GIT地址:

https://github.com/Golangltd/codeclass
Go语言多任务超时处理-channel实现demo

Golang语言社区


以上所述就是小编给大家介绍的《Go语言多任务超时处理-channel实现demo》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

The Everything Store

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》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

html转js在线工具
html转js在线工具

html转js在线工具