use const LogTimeInterval

This commit is contained in:
Serene Han 2016-02-28 13:16:12 -08:00
parent 5aae41c901
commit 8a8273e972

View file

@ -5,6 +5,10 @@ import (
"time" "time"
) )
const (
LogTimeInterval = 5
)
type BytesInfo struct { type BytesInfo struct {
outboundChan chan int outboundChan chan int
inboundChan chan int inboundChan chan int
@ -33,18 +37,18 @@ func (b *BytesInfo) Log() {
b.outbound += amount b.outbound += amount
b.outEvents++ b.outEvents++
last := time.Now() last := time.Now()
if time.Since(last) > time.Second*5 { if time.Since(last) > time.Second*LogTimeInterval {
last = time.Now() last = time.Now()
output() output()
} }
case amount = <-b.inboundChan: case amount = <-b.inboundChan:
b.inbound += amount b.inbound += amount
b.inEvents++ b.inEvents++
if time.Since(last) > time.Second*5 { if time.Since(last) > time.Second*LogTimeInterval {
last = time.Now() last = time.Now()
output() output()
} }
case <-time.After(time.Second * 5): case <-time.After(time.Second * LogTimeInterval):
if b.inEvents > 0 || b.outEvents > 0 { if b.inEvents > 0 || b.outEvents > 0 {
output() output()
} }