ethdb/leveldb: use timer instead of time.After (#21066)

This commit is contained in:
ucwong 2020-05-26 17:03:37 +08:00 committed by GitHub
parent 2f66a8d614
commit 7ddb40239b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -248,6 +248,9 @@ func (db *Database) meter(refresh time.Duration) {
merr error
)
timer := time.NewTimer(refresh)
defer timer.Stop()
// Iterate ad infinitum and collect the stats
for i := 1; errc == nil && merr == nil; i++ {
// Retrieve the database stats
@ -399,7 +402,8 @@ func (db *Database) meter(refresh time.Duration) {
select {
case errc = <-db.quitChan:
// Quit requesting, stop hammering the database
case <-time.After(refresh):
case <-timer.C:
timer.Reset(refresh)
// Timeout, gather a new set of stats
}
}