当前位置:网站首页>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")
}
}
}
边栏推荐
- Methods of adding styles to native JS
- Go 4 modes Singleton
- [LeetCode] 存在重复元素【217】
- UE4 UI adaptive screen
- go 条件变量
- [LeetCode] 数组中的第K个最大元素【215】
- Jerry's modification does not require long press the boot function [chapter]
- How should programmers write logs
- 钟薛高回应产品1小时不化:含固体成分 融化不能变成水
- Hanging mirror security won four global infosec awards on rsac2022
猜你喜欢
![[foreign journal] sleep and weight loss](/img/81/42dcfae19e72a0bc761cb7a40fe5d5.jpg)
[foreign journal] sleep and weight loss

【喜欢的诗词】好了歌

悬镜安全在RSAC2022上斩获Global InfoSec Awards四项大奖
![[羊城杯2020]easyphp](/img/12/da28f738e50e625b0a66a94af3703d.png)
[羊城杯2020]easyphp

【板栗糖GIS】arcmap—为什么使用自定义捕捉的时候,经典捕捉的勾要去掉呢?

kubernetes 使用主机名将 pod 分配在指定节点上

`Usage of ${}`

World Environment Day | Chow Tai Fook serves wholeheartedly to promote carbon reduction and environmental protection

创新实力再获认可!腾讯安全MSS获2022年度云原生安全守护先锋

P1007 独木桥
随机推荐
钟薛高回应产品1小时不化:含固体成分 融化不能变成水
Oracle cursor
[leetcode] there are duplicate elements [217]
[leetcode] reverse string [344]
杰理之样机在多次触摸后会触发关机【篇】
Go four singleton modes
Dahua cloud native load balancing article - the passenger flow of small restaurants has increased
[Luogu p1541] tortoise chess [DP]
MySQL reset password, forget password, reset root password, reset MySQL password
Webrtc audio and video capture and playback examples and mediastream media stream analysis
Objects and object variables
`Usage of ${}`
U++ learning note pile
[LeetCode] 反转字符串中的单词 III【557】
[LeetCode] 存在重复元素【217】
PHP implements querying the data matching the date of birth according to the entered age
Introduction and response to high concurrency
Go语言sqlx库操作SQLite3数据库增删改查
Kubernetes uses the host name to allocate the pod on the specified node
`${}`的用法