当前位置:网站首页>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")
}
}
}
边栏推荐
- How should programmers write logs
- 数据库系统概论第一章简答题-期末考得怎么样?
- [shutter] shutter application theme (themedata | dynamic modification theme)
- Baidu AI Cloud - create a face recognition application
- 存储单位换算
- php实现根据输入的年龄查询出生日期符合的数据
- kubernetes 使用主机名将 pod 分配在指定节点上
- 基于ASP.net的手机销售管理系统(二手手机销售管理系统)+ASP.NET+C#语言+VS2010+数据库可以用于课设、毕设学习
- Mathematical modeling -- graph and network models and methods (I)
- 用sentinel熔断比例阈值改不了,设置慢调用比例没效果
猜你喜欢

基于ASP.net的手机销售管理系统(二手手机销售管理系统)+ASP.NET+C#语言+VS2010+数据库可以用于课设、毕设学习

小鹏P7出事故,安全气囊未弹出,这正常吗?

Task and privilege level protection
![[shutter] shutter application theme (themedata | dynamic modification theme)](/img/77/6b0082368943aee7108ac550141f28.gif)
[shutter] shutter application theme (themedata | dynamic modification theme)

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

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

Oracle-游标

It's not easy to say I love you | use the minimum web API to upload files (swagger support) # yyds dry inventory #
![[foreign journal] sleep and weight loss](/img/81/42dcfae19e72a0bc761cb7a40fe5d5.jpg)
[foreign journal] sleep and weight loss

Wait to solve the zombie process
随机推荐
用sentinel熔断比例阈值改不了,设置慢调用比例没效果
傑理之修改不需要長按開機功能【篇】
杰理之样机无触摸,拆机之后重新安装变正常【篇】
NC24325 [USACO 2012 Mar S]Flowerpot
U++ learning notes - relaxation
PHP微信抢红包的算法
数据库系统概论第一章简答题-期末考得怎么样?
Golang的学习路线
杰理之修改不需要长按开机功能【篇】
杰理之快速触摸不响应问题【篇】
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 total nutrition products
Market Research - current market situation and future development trend of night vision goggles for pilots
PHP wechat red packet grabbing algorithm
go 4种单例模式
图形视图框架
#include errors detected. Please update your includePath.
《乔布斯传》英文原著重点词汇笔记(十一)【 chapter nine】
Oracle-PL/SQL编程
钟薛高回应产品1小时不化:含固体成分 融化不能变成水