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 ( var (
flushMemoryTicker = time.Tick(t.flushMemoryInterval) flushMemoryTicker = time.Tick(t.flushMemoryInterval)
writeMemoryTicker = time.Tick(t.writeMemoryInterval) writeMemoryTicker = time.Tick(t.writeMemoryInterval)
stopReport = make(chan bool)
) )
defer func() { close(stopReport) }()
go func() { go func() {
reportTicker := time.Tick(time.Second) reportTicker := time.Tick(time.Second)
for { for {
<-reportTicker select {
case <-reportTicker:
t.reportQueues() t.reportQueues()
case <-stopReport:
return
}
} }
}() }()