当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
数据库JDBC DAO层方法
Uos统信系统 IP地址以及完整主机名配置
MySQL stored procedure study notes (based on 8.0)
Unity Day02
Visualization and Animation Technology (VR System)
淘宝分布式文件系统存储(二)
2020-03-27
C语言静态变量static的分析
第九篇 ApplicationContext初始化
通过socks5代理下载webrtc源码错误:curl: (7) Can't complete SOCKS5 connection xx.xx.xx.xx
MySQL索引
把DocumentsandSettings迁移到别的盘
如何在网页标题栏中加入图片!
ssm pom文件依赖 web.xml配置
网络通信与Socket编程概述
webrtc代码解读一:音频数据的接收解码播放过程
C# 剪裁图片内容区域
LeetCode_Nov_4th_Week
Vmmem process (WSL2) consumes huge amount of memory
Pfsense漏洞复现(CVE-2021-41282)









