From 56469e3425d77edbdc2eae3d1653a9827440bfa4 Mon Sep 17 00:00:00 2001 From: Lorenzo Manacorda Date: Mon, 26 Sep 2016 17:31:04 +0200 Subject: [PATCH] exit loop using channel --- .../procspy/background_reader_linux.go | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/probe/endpoint/procspy/background_reader_linux.go b/probe/endpoint/procspy/background_reader_linux.go index bcd011656..e27cfa03a 100644 --- a/probe/endpoint/procspy/background_reader_linux.go +++ b/probe/endpoint/procspy/background_reader_linux.go @@ -101,18 +101,18 @@ func (br *backgroundReader) loop(walker process.Walker) { if len(result.sockets) != 0 { log.Info("Received results from THE loop, exiting loop") - return + br.stopc <- struct{}{} + } else { + // Schedule next walk and adjust its rate limit + walkTime := time.Since(begin) + rateLimitPeriod, restInterval = scheduleNextWalk(rateLimitPeriod, walkTime) + ticker.Stop() + ticker = time.NewTicker(rateLimitPeriod) + pWalker.tickc = ticker.C + + walkc = nil // turn off until the next loop + tickc = time.After(restInterval) // turn on } - // Schedule next walk and adjust its rate limit - walkTime := time.Since(begin) - rateLimitPeriod, restInterval = scheduleNextWalk(rateLimitPeriod, walkTime) - ticker.Stop() - ticker = time.NewTicker(rateLimitPeriod) - pWalker.tickc = ticker.C - - walkc = nil // turn off until the next loop - tickc = time.After(restInterval) // turn on - case <-br.stopc: pWalker.stop() ticker.Stop()