当前位置:网站首页>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)
}
}边栏推荐
- Day13 (inner class, anonymous inner class, API common class)
- Which securities company is good for opening a mobile account? Is it safe to open a mobile account?
- Mongodb delete data
- The locally developed SAP ui5 application is deployed to the ABAP server to perform error analysis
- Technology inventory: past, present and future of Message Oriented Middleware
- JS implementation mouse can achieve the effect of left and right scrolling
- Farewell to Lombok in 996
- Cnpm installation
- Day21 JMeter usage basis
- Ethernet
猜你喜欢

Jenkins installation and configuration

Instant messaging project (I)

Code learning-cvpr2020 unsupervised domain adaptive semantic segmentation: intra advance

Trouble of setting table property to null
Configuration file ui5 local in SAP ui5 tools Configuration points of yaml

Monkey test of APP automation

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

Mongodb delete data
Websocket in the promotion of vegetable farmers

Laravel8 fill data
随机推荐
2.20 learning content
Try with resource close resource flow
05 virtual machine stack
Introduction to sap ui5 tools
What is the use of the subprocess module
A method of automatic continuation of previous tables in word table
同花顺软件究竟是什么?网上开户安全么?
MySQL tuning --01--- optimization steps and system performance parameters
Introduction to MySQL test run test framework
C simple operation mongodb
Guava new collection type
手机开户一般哪个证券公司好?手机开户是安全么?
Day19 (variable parameter, enhanced for loop traversal, generic wildcard <? >, TreeSet, linkedhashset, nested traversal of sets, set set, static import,)
CVPR2021-Semi-supervised Domain Adaptation based on Dual-level Domain Mixing for Semantic Segmentati
MySQL tuning -- 02 -- slow query log
Understanding of process, thread, task queue, event loop, macro task, micro task, execution stack and other concepts in JS
No one reads the series. Source code analysis of copyonwritearraylist
Soft exam information system project manager_ Management Science (Operations Research) 2--- senior information system project manager of soft test 034
1.5.3 use tcpdump to observe ARP communication process
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.