当前位置:网站首页>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)
}
}边栏推荐
- Volatile and JMM memory models
- Kyma application connectivity feature introduction
- Jenkins installation and configuration
- Configuration file ui5 local in SAP ui5 tools Configuration points of yaml
- C simple operation mongodb
- An example of recursion, the full permutation problem of 1~n
- Various errors and solutions encountered when deploying SAP ui5 application to ABAP server with SAP Fiori tools
- [QT] for multithreaded programs, do not use the printf() function to print out
- Excel splits a worksheet into multiple worksheets according to conditions, and how to split multiple worksheets into independent tables
- [JS basic review] scope, this, closure
猜你喜欢
SAP ui5 Application Development Tutorial Part 30 - parameter transfer in the routing process of SAP ui5

Use of pytorch tensorboard

Depth of binary tree

MySQL operation JSON
Technology Review: what is the evolution route of container technology? What imagination space is there in the future?

Deep analysis of recursion in quick sorting
SAP ui5 beginner tutorial No. 28 - Introduction to the integration test tool OPA for SAP ui5 applications

Mongodb basic concept learning - set

Mirror image of binary tree

Click to send text messages without response is a common problem for many users in building the elegant grass Dragonfly Q system - solve the problem of clicking to send text messages without response
随机推荐
Design of IM login server and message server
C switch nested syntax
CST8227
Monkey test of APP automation
Trial version of routing history and routing back and history of SAP ui5
Soft exam information system project manager_ Information system security management - Senior Information System Project Manager of soft test 026
Noi Mathematics: Dirichlet convolution
Introduction to sap ui5 tools
Timed thread pool
The k-th node of the binary search tree [sword finger offer]
Technology inventory: Technology Evolution and Future Trend Outlook of cloud native Middleware
Go quiz: considerations for function naming return value from the go interview question (more than 80% of people answered wrong)
HashSet implementation class
Leetcode topic [array] -36- effective Sudoku
Try with resource close resource flow
Understanding the dynamic mode of mongodb document
Guava-IO
Interview experience - list of questions
Instant messaging project (I)
Technology inventory: past, present and future of Message Oriented Middleware