当前位置:网站首页>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
}
}
边栏推荐
- How to perform power regression in R
- Why useevent is not good enough
- Differences between get and post request modes
- Vite+web3: referenceerror: process is not defined
- Is there a security risk in opening an account online? What to do if the business department opening an account nearby is far away from home. Is there any capital requirement for opening an account?
- Introduction and download of nine npp\gpp datasets
- 面试算法 - 字符串问题总结
- JS picture switching case
- 微服务系统设计——数据模型与系统架构设计
- What makes data analysts good- Cassie Kozyrkov
猜你喜欢

SDL: cannot play audio after upgrading openaudio to openaudiodevice

Wechat applet development - Implementation of rotation chart

BOM(Browser Object Model)

为什么 Nodejs 这么快?

论文解读(SR-GNN)《Shift-Robust GNNs: Overcoming the Limitations of Localized Graph Training Data》

The verifiable certificate of geoscience remote sensing industry

Introduction to alos satellite

What is decision intelligence?

Get max value of a bit column - get max value of a bit column

Mcu-08 interrupt system and external interrupt application
随机推荐
Bisection function template
Nokov motion capture system makes it possible for multi field cooperative UAV to build independently
「碎语杂记」这事儿不安全
Navigator object
1: Mosaic of 100W basic geographic information data
Application service access configuration parameters
使用阿里云RDS for SQL Server性能洞察优化数据库负载-初识性能洞察
应用程序DDoS攻击原理及防御方法
How do programmers do we media?
如何在 R 中执行幂回归
Introduction to alos satellite
Get the actual name of the method parameter through the parameter
《Go题库·11》channel的应用场景
微服务系统设计——子服务项目构建
微服务系统设计——数据模型与系统架构设计
Interpreting harmonyos application and service ecology
Flutter dart regular regexp special characters $, () (IV)
Remote sensing Forum
Microservice system design -- interface document management design
【Leetcode】旋转系列(数组、矩阵、链表、函数、字符串)