当前位置:网站首页>Go uses channel to control concurrency
Go uses channel to control concurrency
2022-06-25 05:58:00 【talen_ hx296】
package main
import (
"fmt"
"time"
)
// Maximum number of concurrent
const MAX_PROCESS = 10
var ch = make(chan string, MAX_PROCESS)
func main() {
for i := 0; i < MAX_PROCESS; i++ {
// start-up go runtine
go recive()
}
time.Sleep(1 * time.Hour)
close(ch)
}
func recive() {
for data := range ch {
DoSomething(data)
}
}
func DoSomething(data string) error {
defer dopanic()
fmt.Sprintf("doing %s...", data)
return nil
}
func dopanic() {
if r := recover(); r != nil {
fmt.Errorf("Error: %+v", r)
}
}边栏推荐
- 05 virtual machine stack
- Code learning-cvpr2020 unsupervised domain adaptive semantic segmentation: intra advance
- MySQL uses the where condition to find strange results: solve
- Interview experience - list of questions
- Word quickly makes multiple single-sided table labels, number plates, etc
- Semantic segmentation cvpr2019-advance: advantageous enterprise minimization for domain adaptation in semantic segmentation
- Go implements LRU cache
- Getting started with Silverlight development 1
- Farewell to Lombok in 996
- No one reads the series. Source code analysis of copyonwritearraylist
猜你喜欢

Soft exam information system project manager_ Information system security management - Senior Information System Project Manager of soft test 026

Only these four instructions are required to operate SQL data
Part 33 of SAP ui5 application development tutorial - trial version of responsiveness of SAP ui5 applications

By inserting a section break, the word header, footer, and page number can start from any page
Yunda's cloud based business in Taiwan construction 𞓜 practical school

HashSet implementation class

MySQL tuning -- 02 -- slow query log

Solve some prompt codes that pychar cannot recognize selenium

Voxel based and second network learning

Invalid bound statement (not found)
随机推荐
[OSPF routing calculation (class I LSA router, class II LSA network, and class III LSA sum net)] -20211228-30
手机开户一般哪个证券公司好?手机开户是安全么?
Configuration file ui5 local in SAP ui5 tools Configuration points of yaml
Learn the interface test, see it is very good, and make a note
You can't specify target table for update in from clause error in MySQL
Vscode voice notes to enrich information (medium)
Incorrect dependency of POM file
Use of pytorch tensorboard
MySQL tuning --01--- optimization steps and system performance parameters
MySQL uses the where condition to find strange results: solve
DOM proficient? What is the difference between node and elment?
Only these four instructions are required to operate SQL data
How SAP ui5 device type detection device API works
Deep analysis of recursion in quick sorting
1.6.3 use tcpdump to observe DNS communication process
SAP ui5 date type sap ui. model. type. Analysis of date parsing format
Various errors and solutions encountered when deploying SAP ui5 application to ABAP server with SAP Fiori tools
JS to realize the encapsulation of the function of obtaining the mouse click position
Technology Review: what is the evolution route of container technology? What imagination space is there in the future?
I got to know data types and function variables for the first time. I learned data types and function variables together today and yesterday, so I saved them in the first issue to record.