当前位置:网站首页>Golang channel reading data
Golang channel reading data
2022-06-25 14:54:00 【-multiflora-】
When reading channel when ,channel It does not close but continuously listens (for Cycle and intChan Turn on )
package main
import (
"fmt"
"time"
)
// WriteData
func writeData(intChan chan int) {
for i:=1;i <= 50;i++{
// Put in the data
intChan <- i
fmt.Printf("writeData Write data =%v\n",i)
time.Sleep(500)
}
close(intChan) // close
}
//readData
func readData(intChan chan int,exitChan chan bool){
for {
v,ok := <- intChan
if !ok{
break
}
fmt.Printf("readData Read the data =%v\n",v)
}
// Finish reading the data
exitChan <- true
close(exitChan)
}
func main(){
// Create two pipes
intChan := make(chan int,50)
exitChan := make(chan bool,1)
go writeData(intChan)
go readData(intChan,exitChan)
//time.Sleep(time.Second * 10)
for {
_,ok := <- exitChan
if !ok{
break
}
}
}
边栏推荐
- 【中國海洋大學】考研初試複試資料分享
- The best time to buy and sell stocks
- Biscuit distribution
- Customization and encapsulation of go language zap library logger
- Disable scrolling in the iPhone web app- Disable scrolling in an iPhone web application?
- How to cut the size of a moving picture? Try this online photo cropping tool
- 电源自动测试系统NSAT-8000,精准高速可靠的电源测试设备
- In 2022, the score line of Guangdong college entrance examination was released, and several families were happy and several worried
- Clinical chemistry | zhangjianzhong / Xu Jian develop single cell precision diagnosis and treatment technology for Helicobacter pylori
- What is the safest app for stock account opening? Tell me what you know
猜你喜欢

Report on Hezhou air32f103cbt6 development board

JS get the height and width corresponding to the box model (window.getcomputedstyle, dom.getboundingclientrect)

多张动图怎样合成一张gif?仅需三步快速生成gif动画图片

Build a minimalist gb28181 gatekeeper and gateway server, establish AI reasoning and 3D service scenarios, and then open source code (I)

JS to add elements to the header, or tail of an array

Clinical chemistry | zhangjianzhong / Xu Jian develop single cell precision diagnosis and treatment technology for Helicobacter pylori

Uniapp cloud packaging app

In 2022, the score line of Guangdong college entrance examination was released, and several families were happy and several worried

电源自动测试系统NSAT-8000,精准高速可靠的电源测试设备

90 后眼中的理想 L9:最简单的产品哲学,造最猛的爆款 | 指南斟
随机推荐
Deconstruction assignment of variables
[untitled]
‘make_ unique’ is not a member of ‘std’
JS to verify whether the string is a regular expression
Flexible layout (display:flex;) Attribute details
What is the difference between escape, encodeuri and encodeuricomponent?
QT file reading -qfile
JGG | 河北大学杜会龙组综述植物泛基因组学研究
Go语言Zap库Logger的定制化和封装使用详解
Add the resources directory under test in idea
p1408
Jaspersoft studio installation
Add a string at the input and textarea cursors
QT database connection
重磅!国产 IDE 发布,由阿里研发,完全开源!(高性能+高定制性)
JS recursion and while
Native JS obtains form data and highlights and beautifies JSON output display
What is the safest app for stock account opening? Tell me what you know
Remove interval (greedy)
Qt: Pro project file