From c09847ec074533e8dddf4c4e62ec370ec62c5a8a Mon Sep 17 00:00:00 2001 From: liuxiaolong <736321739@qq.com> Date: 星期六, 29 六月 2019 10:08:26 +0800 Subject: [PATCH] fix --- service/FaceSdkService.go | 25 ++++++++++--------------- 1 files changed, 10 insertions(+), 15 deletions(-) diff --git a/service/FaceSdkService.go b/service/FaceSdkService.go index b099565..fcdcd04 100644 --- a/service/FaceSdkService.go +++ b/service/FaceSdkService.go @@ -19,6 +19,7 @@ type FaceSdkService struct { File *multipart.File Id string + Result []*protomsg.ResultFaceExtCom } const ( @@ -115,33 +116,27 @@ } } -func (s *FaceSdkService) GetFaceFea() (feas []*protomsg.ResultFaceExtCom,err error){ +func (s *FaceSdkService) GetFaceFea(){ var wg sync.WaitGroup wg.Add(1) - ch := make(chan []*protomsg.ResultFaceExtCom,0) - go func() { + ticker := time.NewTicker(time.Second * 3) + go func(ticker *time.Ticker, s *FaceSdkService) { + defer ticker.Stop() + defer wg.Done() + for { select { - case <-time.Tick(time.Second*10): - ch <- nil - wg.Done() + case <-ticker.C: return default: if feas,ok := resultMap[s.Id];ok { - fmt.Println("faceFea got!!!") - ch <- feas + s.Result = feas return } } } - }() + }(ticker, s) wg.Wait() - msg := <- ch - if msg != nil { - return msg,nil - } else { - return msg,errors.New("no fea") - } } func readTestImgFile() protomsg.Image{ -- Gitblit v1.8.0