首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >[Go小技巧] 实现Go经典的消息队列处理协程

[Go小技巧] 实现Go经典的消息队列处理协程

作者头像
andeya
发布2019-04-04 15:16:55
发布2019-04-04 15:16:55
3K0
举报
文章被收录于专栏:Go实战Go实战
代码语言:javascript
复制
type Engine struct {
	queue chan interface{}
}

// 推送请求到队列
func (e *Engine) Push(req interface{}) {
	e.queue <- req
}

// 开启服务协程
func (e *Engine) Serve() {
	go func() {
		for {
			req := <-e.queue
			// do some thing
			_ = req
		}
	}()
}

(adsbygoogle = window.adsbygoogle || []).push({});

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2016/09/02 ,如有侵权请联系 cloudcommunity@tencent.com 删除
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档