当前位置:网站首页>Application scenarios of channel of go question bank · 11
Application scenarios of channel of go question bank · 11
2022-06-24 18:50:00 【GolangRoadmap】
*「 title 」GOLANG ROADMAP Community
*
「 answer 」(engine)
channel It is applicable to scenarios where data flows in multiple processes , There are many practical applications :
① Task timing
For example, timeout processing :
select {
case <-time.After(time.Second):
Timing task
select {
case <- time.Tick(time.Second)
② Decoupling producers and consumers
Producers and consumers can be decoupled , Producers only need to go to channel send data , And consumers just go from channel Get data in .
③ Control concurrency
Take reptiles for example , Such as crawling 1w Data , Concurrent crawling is required to improve efficiency , But the concurrency should not be too large , Can pass channel To control the concurrency scale , For example, support at the same time 5 Concurrent tasks :
ch := make(chan int, 5)
for _, url := range urls {
go func() {
ch <- 1
worker(url)
<- ch
}
}
边栏推荐
- This is not safe
- Microservice system design -- data model and system architecture design
- JS deep understanding of functions
- Analysis on the issue of raising the right of MSSQL in 2021 secondary vocational group network security competition in Shandong Province
- Leetcode question 136 [single number]
- Why is nodejs so fast?
- JS picture display and hiding cases
- About pyqt5 to realize paging function (one window implements different interfaces)
- UnityShader 世界坐标不随模型变化
- Network security database penetration of secondary vocational group in 2022
猜你喜欢

Network security database penetration of secondary vocational group in 2022

微服務系統設計——子服務項目構建

Mqtt protocol usage of LabVIEW

JS local storage

Flutter dart regular regexp special characters $, () (IV)

Graph traversal (BFS and DFS) C language pure handwriting
![717.1-bit and 2-bit characters [sliding window]](/img/61/449566d2a8efbd403ae0361f839683.jpg)
717.1-bit and 2-bit characters [sliding window]

696. count binary substring

Redis learning -- list of redis operations

Different JVM
随机推荐
Microservice system design - sub service project construction
Monotone stack template
Value passing and reference passing of value types and reference types in CSharp
Volcano devient l'ordonnanceur de lots par défaut Spark
Analysis on the issue of raising the right of MSSQL in 2021 secondary vocational group network security competition in Shandong Province
How to use Fisher's least significant difference (LSD) in R
Several ways of connecting upper computer and MES
NOKOV动作捕捉系统使多场协同无人机自主建造成为可能
JS clothing photo album case
2022 network security C module of the secondary vocational group scans the script of the surviving target aircraft (municipal, provincial and national)
1: Mosaic of 100W basic geographic information data
The mixed calculation of rpx and PX in JS by the uniapp applet
ASP. Net hosting uploading file message 500 error in IIS
Wechat applet to realize stacked rotation
717.1-bit and 2-bit characters [sliding window]
Microservice system design -- data model and system architecture design
如何在 R 中执行幂回归
解读HarmonyOS 应用与服务生态
Introduction and download tutorial of two types of soil data
Make track map