2 Star 3 Fork 1

vendors/gin-gonic-gin

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
rooms.go 667 Bytes
一键复制 编辑 原始数据 按行查看 历史
Manu Mtz-Almeida 提交于 2015-05-12 19:23 . Adds realtime-chat example code
package main
import "github.com/dustin/go-broadcast"
var roomChannels = make(map[string]broadcast.Broadcaster)
func openListener(roomid string) chan interface{} {
listener := make(chan interface{})
room(roomid).Register(listener)
return listener
}
func closeListener(roomid string, listener chan interface{}) {
room(roomid).Unregister(listener)
close(listener)
}
func deleteBroadcast(roomid string) {
b, ok := roomChannels[roomid]
if ok {
b.Close()
delete(roomChannels, roomid)
}
}
func room(roomid string) broadcast.Broadcaster {
b, ok := roomChannels[roomid]
if !ok {
b = broadcast.NewBroadcaster(10)
roomChannels[roomid] = b
}
return b
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/vendors/gin-gonic-gin.git
git@gitee.com:vendors/gin-gonic-gin.git
vendors
gin-gonic-gin
gin-gonic-gin
v1.1.4

搜索帮助