当前位置:网站首页>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
}
}
边栏推荐
- Sr-gnn shift robot gnns: overlapping the limitations of localized graph training data
- Data driven decision making: Decision intelligence and design thinking
- Graph traversal (BFS and DFS) C language pure handwriting
- Wechat applet development - Implementation of rotation chart
- MySQL basic commands
- 论文解读(SR-GNN)《Shift-Robust GNNs: Overcoming the Limitations of Localized Graph Training Data》
- BOM(Browser Object Model)
- Mcu-08 interrupt system and external interrupt application
- JS picture switching case
- Vite+web3: referenceerror: process is not defined
猜你喜欢
Sentry series satellite introduction and download tutorial
110. balanced binary tree
JS deep understanding of functions
Why is nodejs so fast?
Volcano成Spark默认batch调度器
History object
Conception de systèmes de micro - services - construction de sous - services
Sr-gnn shift robot gnns: overlapping the limitations of localized graph training data
Recommend a distributed JVM monitoring tool, which is very practical!
JS position operation
随机推荐
Interpreting harmonyos application and service ecology
程序员如何做自媒体?
论文解读(SR-GNN)《Shift-Robust GNNs: Overcoming the Limitations of Localized Graph Training Data》
Use ado Net call stored procedure
Building MVC system based on three-tier structure
Conception de systèmes de micro - services - construction de sous - services
[leetcode] rotation series (array, matrix, linked list, function, string)
微服务系统设计——数据模型与系统架构设计
API管理之利剑 -- Eolink
Wechat applet to realize stacked rotation
时间溯源的系统设计思路
JS local storage
Knowledge points in T-SQL
Microservice system design - sub service project construction
History object
论文解读(SR-GNN)《Shift-Robust GNNs: Overcoming the Limitations of Localized Graph Training Data》
如何在 R 中执行幂回归
上位机与MES对接的几种方式
NOKOV动作捕捉系统使多场协同无人机自主建造成为可能
Bisection function template