Merge pull request #5755 from nekto0n/reuse-timer

Reuse timer in backend.run.
This commit is contained in:
Xiang Li 2016-06-23 07:28:09 -07:00 committed by GitHub
commit 5247702d8d

View File

@ -179,15 +179,17 @@ func (b *backend) Size() int64 {
func (b *backend) run() {
defer close(b.donec)
t := time.NewTimer(b.batchInterval)
defer t.Stop()
for {
select {
case <-time.After(b.batchInterval):
case <-t.C:
case <-b.stopc:
b.batchTx.CommitAndStop()
return
}
b.batchTx.Commit()
t.Reset(b.batchInterval)
}
}