当前位置:网站首页>go 多线程数据搜索
go 多线程数据搜索
2022-07-02 22:07:00 【给我一瓶冰阔洛】
go 多线程数据搜索
package main
import (
"fmt"
"strings"
"time"
)
type User struct {
Email string
Name string
}
var DataBase = []User{
{"[email protected]","张三"},
{"[email protected]","张李四"},
{"[email protected]","王五"},
{"[email protected]","赵六"},
{"[email protected]","李七"},
{"[email protected]","武松"},
{"[email protected]","林冲"},
{"[email protected]","晁盖"},
{"[email protected]","李逵"},
{"[email protected]","宋江"},
{"[email protected]","鲁智深"},
{"[email protected]","吴用"},
}
type Worker struct {
users []User
ch chan *User
name string
}
func NewWorker(users []User, ch chan *User, name string)*Worker{
return &Worker{
users: users,
ch: ch,
name: name,
}
}
func (w*Worker)Find(email string){
for i:=range w.users{
user := &w.users[i]
if strings.Contains(user.Email, email){
w.ch <- user
}
}
}
func main() {
email := "sdfg5sfdg5"
ch := make(chan *User)
go NewWorker(DataBase[:3], ch,"吴用").Find(email)
go NewWorker(DataBase[3:8], ch,"吴用").Find(email)
go NewWorker(DataBase[8:], ch,"吴用").Find(email)
for {
select {
case user := <-ch:
fmt.Println(user.Email,user.Name)
return
case <-time.After(time.Second):
fmt.Println("find-ing")
}
}
}
边栏推荐
- [QT] Q multithreaded development - Analysis of multithreaded application examples (Mandelbrot)
- Market Research - current market situation and future development trend of handheld wound imaging equipment
- [001] [arm-cortex-m3/4] internal register
- 【ODX Studio编辑PDX】-0.1-如何快速查看各Variant变体间的支持的诊断信息差异(服务,Sub-Function...)
- Pointer - function pointer
- Niuke: Dragon and dungeon games
- 傑理之修改不需要長按開機功能【篇】
- Simpleitk use - 3 Common operations
- [micro service sentinel] rewrite Sentinel's interface blockexceptionhandler
- [autosar-dcm] - 4.3-how UDS $22 and $2e services read and write NVM data
猜你喜欢
![[shutter] shutter custom fonts (download TTF fonts | pubspec.yaml configure font resources | synchronize resources | globally apply fonts | locally apply fonts)](/img/27/8594ba0b49d5008b7469967babed17.jpg)
[shutter] shutter custom fonts (download TTF fonts | pubspec.yaml configure font resources | synchronize resources | globally apply fonts | locally apply fonts)

Niuke: Dragon and dungeon games

牛客网:最大子矩阵

Commodity information management system (C language document version)

Task and privilege level protection

Graphic view frame

数学建模——图与网络模型及方法(一)

Oracle PL / SQL programming

uniapp微信登录返显用户名和头像

Socket socket c/s end process
随机推荐
Notes on key vocabulary in the English original of the biography of jobs (11) [chapter nine]
LxC terminal login method
SimpleITK使用——4. 奇怪的問題
[LeetCode] 反转字符串中的单词 III【557】
[error record] the flutter reports an error (could not read script 'xxx\flutter\u tools\gradle\app\u plugin\u loader.gradle')
Market Research - current situation and future development trend of cell-based seafood market
Socket套接字C/S端流程
数学建模——图与网络模型及方法(一)
Mathematical modeling -- graph and network models and methods (I)
地方经销商玩转社区团购模式,百万运营分享
Market Research - current market situation and future development trend of aircraft wireless intercom system
Pointer - function pointer
Oracle cursor
NC24325 [USACO 2012 Mar S]Flowerpot
Struct, bit segment, enumeration, union
Oracle-游标
Dahua cloud native load balancing article - the passenger flow of small restaurants has increased
Il n'est pas nécessaire d'appuyer longtemps sur la fonction de démarrage pour modifier Jelly [chapitre]
Film and television excerpts
Introduction to database system Chapter 1 short answer questions - how was the final exam?