当前位置:网站首页>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")
}
}
}
边栏推荐
- go 条件变量
- [chestnut sugar GIS] ArcMap - how to batch modify the font, color, size, etc. of annotation elements
- Go four singleton modes
- Objects and object variables
- World Environment Day | Chow Tai Fook serves wholeheartedly to promote carbon reduction and environmental protection
- Jerry's charge unplugged, unable to touch the boot [chapter]
- kubernetes 使用主机名将 pod 分配在指定节点上
- How can I use knockout's $parent/$root pseudovariables from inside a . computed() observable?
- 【板栗糖GIS】arcscene—如何做出有高度的高程图
- [micro service sentinel] rewrite Sentinel's interface blockexceptionhandler
猜你喜欢
随机推荐
[羊城杯2020]easyphp
Oracle PL / SQL programming
Jatpack------LiveData
大一学习分享
What is the'function'keyword used in some bash scripts- What is the 'function' keyword used in some bash scripts?
QT qsplitter splitter
Higher order operation of bits
世界环境日 | 周大福用心服务推动减碳环保
Oracle-游标
海思3559万能平台搭建:在截获的YUV图像上画框
The threshold value of fusing proportion cannot be changed with sentinel, and setting the slow call proportion has no effect
Hanging mirror security won four global infosec awards on rsac2022
Uniapp wechat login returns user name and Avatar
牛客网:龙与地下城游戏
Array advanced improvement
Jerry's charge unplugged, unable to touch the boot [chapter]
Introduction to database system Chapter 1 short answer questions - how was the final exam?
odoo13搭建医院HRP环境(详细步骤)
[foreign journal] sleep and weight loss
Niuke: Dragon and dungeon games

![NC24325 [USACO 2012 Mar S]Flowerpot](/img/cf/86acbcb524b3af0999ce887c877781.png)






