当前位置:网站首页>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
}
}
边栏推荐
- Architecture decryption from distributed to microservice: several common microservice architecture schemes
- 2022 network security C module of the secondary vocational group scans the script of the surviving target aircraft (municipal, provincial and national)
- Get max value of a bit column - get max value of a bit column
- Palindrome string (two methods)
- Why are life science enterprises on the cloud in succession?
- Conception de systèmes de micro - services - construction de sous - services
- Make track map
- History object
- JS picture display and hiding cases
- 110. balanced binary tree
猜你喜欢

Vite+web3:报错出现ReferenceError: process is not defined

Mqtt protocol usage of LabVIEW

Introduction, download and use of global meteorological data CRU ts from 1901 to 2020

建立自己的网站(8)

时间溯源的系统设计思路

Remote sensing Forum

360 digital released information security trends in January: 120000 fraud risks were captured and users were reminded 2.68 million times

Different JVM

DOM (document object model)

Wechat applet development - Implementation of rotation chart
随机推荐
Architecture decryption from distributed to microservice: several common microservice architecture schemes
Volcano devient l'ordonnanceur de lots par défaut Spark
110. balanced binary tree
JS event details
Interpreting harmonyos application and service ecology
717.1-bit and 2-bit characters [sliding window]
SAP license: what is ERP supply chain
Vite+web3:报错出现ReferenceError: process is not defined
Solve the problem that the MapReduce program console does not have log information warn please initialize the log4j system properly
JS deep understanding of functions
Wechat applet development - Implementation of rotation chart
Differences between get and post request modes
【Leetcode】旋转系列(数组、矩阵、链表、函数、字符串)
FROM_ GLC introduction and data download tutorial
Executing SQL statements with parameterized commands
SAP license: SAP s/4 Hana module function introduction
JS picture switching case
Flutter dart regular regexp special characters $, () (IV)
JDBC writes Chinese garbled code to the database
Network security database penetration of secondary vocational group in 2022