当前位置:网站首页>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)
}
}边栏推荐
- Tutorial 35 of SAP ui5 application development - how to deploy locally developed SAP ui5 applications to ABAP server for trial reading
- Monkey test of APP automation
- ThreadLocal
- Interface learning
- Soft exam information system project manager_ Information system security management - Senior Information System Project Manager of soft test 026
- Vscode voice notes to enrich information (medium)
- SAP ui5 date type sap ui. model. type. Analysis of date parsing format
- HashSet implementation class
- Guava-IO
- SAP ui5 beginner tutorial No. 27 - unit test tool quNit introduction trial version for SAP ui5 application
猜你喜欢
Interviewer: what is an iterator? What is the relationship between async await and iterators?

By inserting a section break, the word header, footer, and page number can start from any page

Semantic segmentation fcns in the wild: pixel level adaptive and constraint based adaptation

No one reads the series. Source code analysis of copyonwritearraylist

Array introduction plus example 01
Introduction to sap ui5 tools

Use of pytorch tensorboard

Timed thread pool

Understanding the dynamic mode of mongodb document
Technology Review: what is the evolution route of container technology? What imagination space is there in the future?
随机推荐
SAP ui5 beginner tutorial No. 28 - Introduction to the integration test tool OPA for SAP ui5 applications
[OSPF routing calculation (class I LSA router, class II LSA network, and class III LSA sum net)] -20211228-30
Differences and connections between sap ui5 and openui5
Farewell to Lombok in 996
MySQL operation JSON
How SAP ui5 device type detection device API works
Use of collection
Analysis of IM project framework
Jenkins installation and configuration
Day22(File,DiGui,FileOutputStream)
ArcGIS Engine + Visual Studio installation tutorial
CSDN cerebral palsy bug has wasted nearly two hours of hard work
Interviewer: what is an iterator? What is the relationship between async await and iterators?
Mongodb basic concept learning - Documentation
Soft exam information system project manager_ Information system security management - Senior Information System Project Manager of soft test 026
50 days countdown! Are you ready for the Landbridge cup provincial tournament?
Getting started with mongodb
Technology inventory: past, present and future of Message Oriented Middleware
Word quickly makes multiple single-sided table labels, number plates, etc
About the definition of pointer variables (personal notes)