From a65dab0d437179c787b18befde35557443c30850 Mon Sep 17 00:00:00 2001 From: miraclesu Date: Wed, 22 Mar 2017 09:30:47 +0800 Subject: [PATCH] =?UTF-8?q?proc:=20=E4=BF=9D=E8=AF=81=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E4=BB=BB=E5=8A=A1=E4=BF=A1=E6=81=AF=E4=B8=80?= =?UTF-8?q?=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/proc.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/models/proc.go b/models/proc.go index 968da64..24f21d8 100644 --- a/models/proc.go +++ b/models/proc.go @@ -134,7 +134,7 @@ type Process struct { running bool hasPut bool - timer *time.Timer + wg sync.WaitGroup done chan struct{} } @@ -216,17 +216,17 @@ func (p *Process) Start() { return } - p.timer = time.NewTimer(time.Duration(conf.Config.ProcReq) * time.Second) p.done = make(chan struct{}) - + p.wg.Add(1) go func() { select { case <-p.done: - case <-p.timer.C: + case <-time.After(time.Duration(conf.Config.ProcReq) * time.Second): if err := p.put(); err != nil { log.Warnf("proc put err: %s", err.Error()) } } + p.wg.Done() }() } @@ -240,10 +240,7 @@ func (p *Process) Stop() error { close(p.done) } - if p.timer != nil { - p.timer.Stop() - } - + p.wg.Wait() err := p.del() p.hasPut = false return err