当前位置:网站首页>golang chan
golang chan
2022-08-04 05:34:00 【_杜竞宁_】
chan:go routine 间消息通道
package main
import (
"log"
"time"
)
type APIHandler struct {
RestartChan chan bool
}
var API = &APIHandler{
RestartChan: make(chan bool),
}
var Debug bool = true
func main(){
log.SetPrefix("[chan] ")
log.Println("start...")
if Debug {
log.SetFlags(log.Lshortfile | log.LstdFlags)
}
go func() {
for range API.RestartChan {
API.Print()
}
}()
for {
API.RestartChan <- true
time.Sleep(1*time.Second)
}
}
func (api *APIHandler) Print(){
log.Println("chan in")
}
result:
[[email protected] chann]# go run chann.go
[chan] 2022/06/15 09:26:57 start...
[chan] 2022/06/15 09:26:57 chann.go:40: chan in
[chan] 2022/06/15 09:26:58 chann.go:40: chan in
[chan] 2022/06/15 09:26:59 chann.go:40: chan in
边栏推荐
猜你喜欢
随机推荐
Memory limit should be smaller than already set memoryswap limit, update the memoryswap at the same
Uos统信系统 Postfix-smtps & Dovecot-imaps
Visualization and Animation Technology (VR System)
树和二叉树
const int * a 与 int * const a 的定义与区别
基于Webrtc和Janus的多人视频会议系统开发7 - publish和subscribe声音设备冲突导致对方听不到声音
Prematurely reached end of stream
JUC锁框架——基于AQS的实现,从ReentrantLock认识独占和共享
普通用户 远程桌面连接 服务器 Remote Desktop Service
淘宝分布式文件系统存储引擎(一)
无一技之长学什么可以做到月入上万?
Uos统信系统控制台欢迎登陆后消息及所处区域配置
键盘扫描码
POI及EasyExcel
通过socks5代理下载webrtc源码错误:curl: (7) Can't complete SOCKS5 connection xx.xx.xx.xx
webrtc代码解读一:音频数据的接收解码播放过程
Operating System Random
strlen 转义字符
[Development miscellaneous][Debug]debug into kernel
Uos统信系统 IP地址以及完整主机名配置