Have goroutine exit on signal via defer block.

This commit is contained in:
Johannes 'fish' Ziemke 2013-04-25 12:12:50 +02:00
parent af7ddc36e2
commit 5043c6fce7

View File

@ -164,15 +164,20 @@ func (t *tieredStorage) Serve() {
var (
flushMemoryTicker = time.Tick(t.flushMemoryInterval)
writeMemoryTicker = time.Tick(t.writeMemoryInterval)
stopReport = make(chan bool)
)
defer func() { close(stopReport) }()
go func() {
reportTicker := time.Tick(time.Second)
for {
<-reportTicker
t.reportQueues()
select {
case <-reportTicker:
t.reportQueues()
case <-stopReport:
return
}
}
}()