当前位置:网站首页>Go multithreaded data search
Go multithreaded data search
2022-07-02 22:56:00 【Give me a bottle of Borneol】
go Multithreaded data search
package main
import (
"fmt"
"strings"
"time"
)
type User struct {
Email string
Name string
}
var DataBase = []User{
{"[email protected]"," Zhang San "},
{"[email protected]"," Zhang Lisi "},
{"[email protected]"," Wang Wu "},
{"[email protected]"," Zhao Liu "},
{"[email protected]"," Li Qi "},
{"[email protected]"," Wusong "},
{"[email protected]"," Lin Chong "},
{"[email protected]"," Chaogai "},
{"[email protected]"," Li Kui "},
{"[email protected]"," Song Jiang "},
{"[email protected]"," lu "},
{"[email protected]"," Wu Yong "},
}
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," Wu Yong ").Find(email)
go NewWorker(DataBase[3:8], ch," Wu Yong ").Find(email)
go NewWorker(DataBase[8:], ch," Wu Yong ").Find(email)
for {
select {
case user := <-ch:
fmt.Println(user.Email,user.Name)
return
case <-time.After(time.Second):
fmt.Println("find-ing")
}
}
}
边栏推荐
- NC50965 Largest Rectangle in a Histogram
- JS syntax ES6, ES7, es8, es9, ES10, es11, ES12 new features (Abstract)
- Webrtc audio and video capture and playback examples and mediastream media stream analysis
- Il n'est pas nécessaire d'appuyer longtemps sur la fonction de démarrage pour modifier Jelly [chapitre]
- 杰理之样机无触摸,拆机之后重新安装变正常【篇】
- Local dealers play the community group purchase mode and share millions of operations
- php实现根据输入的年龄查询出生日期符合的数据
- 解决Chrome浏览器和Edeg浏览器主页被篡改的方法
- World Environment Day | Chow Tai Fook serves wholeheartedly to promote carbon reduction and environmental protection
- I admire that someone explained such an obscure subject as advanced mathematics so easily
猜你喜欢
Wait to solve the zombie process
Jatpack------LiveData
Go语言sqlx库操作SQLite3数据库增删改查
Objects and object variables
Higher order operation of bits
#include errors detected. Please update your includePath.
Addition, deletion, modification and query of handwritten ORM (object relationship mapping)
Oracle cursor
海思3559万能平台搭建:在截获的YUV图像上画框
Kubernetes uses the host name to allocate the pod on the specified node
随机推荐
【洛谷P1541】乌龟棋【DP】
`Usage of ${}`
stop slave卡住--事务的事件没有复制完整
【板栗糖GIS】global mapper 如何通过dsm批量制作贴地等高线
What is the'function'keyword used in some bash scripts- What is the 'function' keyword used in some bash scripts?
加油站[问题分析->问题转换->贪心]
JS syntax ES6, ES7, es8, es9, ES10, es11, ES12 new features (Abstract)
Rails 3 activerecord: sort by association count - rails 3 activerecord: order by count on Association
【板栗糖GIS】arcscene—如何做出有高度的高程图
[autosar-dcm] - 4.3-how UDS $22 and $2e services read and write NVM data
杰理之修改不需要长按开机功能【篇】
Radis:Linux上安装Redis(步骤)
对象与对象变量
Jatpack------LiveData
Solve the error of changing the selected file when uploading excel file. Net:: err_ UPLOAD_ FILE_ CHANGED
【板栗糖GIS】arcmap—如何批量修改注记要素的字体,颜色,大小等
Local dealers play the community group purchase mode and share millions of operations
钟薛高回应产品1小时不化:含固体成分 融化不能变成水
中国信通院、清华大学、腾讯安全,云原生安全产学研用强强联合!
送给即将工作的自己