当前位置:网站首页>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")
}
}
}
边栏推荐
- 【板栗糖GIS】arcmap—如何批量修改注记要素的字体,颜色,大小等
- kubernetes 使用主机名将 pod 分配在指定节点上
- 540. Single element in ordered array
- uniapp微信登录返显用户名和头像
- 悬镜安全在RSAC2022上斩获Global InfoSec Awards四项大奖
- UE4 game architecture learning notes
- How should programmers write logs
- [LeetCode] 存在重复元素【217】
- Market Research - current situation and future development trend of herringbone gear Market
- 用sentinel熔断比例阈值改不了,设置慢调用比例没效果
猜你喜欢

开发者分享 | HLS, 巧用AXI_master总线接口指令的定制并提升数据带宽-面积换速度...

Jatpack------LiveData
![[001] [arm-cortex-m3/4] internal register](/img/49/a0eceac1a67267216dd9b2566033a1.jpg)
[001] [arm-cortex-m3/4] internal register
![[error record] the flutter reports an error (could not read script 'xxx\flutter\u tools\gradle\app\u plugin\u loader.gradle')](/img/02/67448df1817e8b34b654722df8ecd4.jpg)
[error record] the flutter reports an error (could not read script 'xxx\flutter\u tools\gradle\app\u plugin\u loader.gradle')
![[foreign journal] sleep and weight loss](/img/81/42dcfae19e72a0bc761cb7a40fe5d5.jpg)
[foreign journal] sleep and weight loss

PMP项目整合管理
![[ODX studio edit PDX] -0.1- how to quickly view the differences in supported diagnostic information between variant variants (service, sub function...)](/img/2b/f31b81cedf37ca187bcaa20dfe0b83.png)
[ODX studio edit PDX] -0.1- how to quickly view the differences in supported diagnostic information between variant variants (service, sub function...)

世界环境日 | 周大福用心服务推动减碳环保

540. Single element in ordered array

小鹏P7出事故,安全气囊未弹出,这正常吗?
随机推荐
PMP项目整合管理
世界环境日 | 周大福用心服务推动减碳环保
杰理之修改不需要长按开机功能【篇】
Dynamic memory allocation (malloc calloc realloc free)
Market Research - current market situation and future development trend of aircraft front wheel steering system
[LeetCode] 回文数【9】
U++ 学习笔记 ----松弛
Market Research - current situation and future development trend of marine clutch Market
U++ 原始内存 学习笔记
[shutter] shutter application theme (themedata | dynamic modification theme)
PHP微信抢红包的算法
傑理之修改不需要長按開機功能【篇】
Market Research - current market situation and future development trend of high tibial osteotomy plate
Radis:Linux上安装Redis(步骤)
'when to use const char * and when to use const char []' - when to use const char * and when to use const char []
[shutter] shutter custom fonts (download TTF fonts | pubspec.yaml configure font resources | synchronize resources | globally apply fonts | locally apply fonts)
How should programmers write logs
U++ 学习笔记 堆
杰理之充电拔出,无法触摸开机【篇】
手写ORM(对象关系映射)增删改查