当前位置:网站首页>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)
}
}边栏推荐
- Voxel based and second network learning
- Go microservice development toolkit
- The locally developed SAP ui5 application is deployed to the ABAP server to perform error analysis
- Linus' speech recordings, which were lost in 1994, were made public
- Various errors and solutions encountered when deploying SAP ui5 application to ABAP server with SAP Fiori tools
- What is SAP sup - Sybase unwired platform
- Tutorial 35 of SAP ui5 application development - how to deploy locally developed SAP ui5 applications to ABAP server for trial reading
- Day19 (variable parameter, enhanced for loop traversal, generic wildcard <? >, TreeSet, linkedhashset, nested traversal of sets, set set, static import,)
- Incorrect dependency of POM file
- ArcGIS Engine + Visual Studio installation tutorial
猜你喜欢

Unsupervised domain adaptation in semantic segmentation:a review unsupervised domain adaptation in semantic segmentation: a review
[kicad image] download and installation

Day22 send request and parameterization using JMeter

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.

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

Mongodb basic concept learning - set

Go implements LRU cache

C switch nested syntax
Yunda's cloud based business in Taiwan construction 𞓜 practical school

Volatile and JMM memory models
随机推荐
1.6.3 use tcpdump to observe DNS communication process
Multithreading and thread pool
Go language map sorting (key/value sorting)
Data7202 statistical analysis
钱堂教育的证券账户安全吗?靠谱吗?
Common cluster deployment schemes in redis
Soft exam information system project manager_ Management Science (Operations Research) -- senior information system project manager of soft test 033
Guava-IO
Technology inventory: Technology Evolution and Future Trend Outlook of cloud native Middleware
同花顺软件究竟是什么?网上开户安全么?
3.2.3 use tcpdump to observe TCP header information (supplement common knowledge of TCP protocol)
Use of pytorch tensorboard
Part 33 of SAP ui5 application development tutorial - trial version of responsiveness of SAP ui5 applications
Trial version of routing history and routing back and history of SAP ui5
Guava immutable set
Use of MySQL variables
JS to realize the encapsulation of the function of obtaining the mouse click position
Mirror image of binary tree
Mongodb basic concept learning - set
Configuration file ui5 local in SAP ui5 tools Configuration points of yaml