当前位置:网站首页>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")
}
}
}
边栏推荐
- [shutter] shutter custom fonts (download TTF fonts | pubspec.yaml configure font resources | synchronize resources | globally apply fonts | locally apply fonts)
- UE4 game architecture learning notes
- 数据库系统概论第一章简答题-期末考得怎么样?
- 【AUTOSAR-DCM】-4.3-UDS $22和$2E服务如何读取和写入NVM数据
- Unity发布WebGL播放声音的一种方法
- 送给即将工作的自己
- NC50965 Largest Rectangle in a Histogram
- 《乔布斯传》英文原著重点词汇笔记(九)【 chapter seven】
- Zhong Xuegao responded that the product will not melt for 1 hour: it contains solid components and cannot melt into water
- 基于ASP.net的手机销售管理系统(二手手机销售管理系统)+ASP.NET+C#语言+VS2010+数据库可以用于课设、毕设学习
猜你喜欢

杰理之、产线装配环节【篇】

位的高阶运算

Socket socket c/s end process

图形视图框架

UE4 游戏架构 学习笔记
![Additional: [login information storage] and [login status verification]; (including: summarizing all the contents of [login information storage] and [login status verification] so far;)](/img/b7/0f543829b57cf2f2544efec4910c17.png)
Additional: [login information storage] and [login status verification]; (including: summarizing all the contents of [login information storage] and [login status verification] so far;)

NC50965 Largest Rectangle in a Histogram
![[LeetCode] 多数元素【169】](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[LeetCode] 多数元素【169】

Commodity information management system (C language document version)

【板栗糖GIS】arcmap—为什么使用自定义捕捉的时候,经典捕捉的勾要去掉呢?
随机推荐
《乔布斯传》英文原著重点词汇笔记(九)【 chapter seven】
php优化foreach中的sql查询
[micro service sentinel] rewrite Sentinel's interface blockexceptionhandler
UE4 game architecture learning notes
杰理之充电拔出,无法触摸开机【篇】
Build your own website (22)
Objects and object variables
建立自己的网站(22)
Leetcode circular linked list (fast and slow pointer) code line by line interpretation
New feature of go1.18: introduce new netip Network Library
JS solution for obtaining the width and height of hidden elements whose display is none
What is the'function'keyword used in some bash scripts- What is the 'function' keyword used in some bash scripts?
大话云原生之负载均衡篇-小饭馆客流量变大了
Market Research - current market situation and future development trend of marine wet exhaust hose
杰理之内置关机电流 1.2uA,之后不能长按开机【篇】
[shutter] shutter custom fonts (download TTF fonts | pubspec.yaml configure font resources | synchronize resources | globally apply fonts | locally apply fonts)
【微服务|Sentinel】重写sentinel的接口BlockExceptionHandler
Notes on key vocabulary in the English original of the biography of jobs (10) [chapter eight]
Additional: [login information storage] and [login status verification]; (including: summarizing all the contents of [login information storage] and [login status verification] so far;)
Dynamic memory allocation (malloc calloc realloc free)