Use time.After instead of tickers.

This commit is contained in:
jholdstock 2022-03-28 14:35:15 +01:00 committed by Jamie Holdstock
parent 9fe6eb8e52
commit c91ec5c697
3 changed files with 5 additions and 11 deletions

View File

@ -379,14 +379,12 @@ func Start(shutdownCtx context.Context, wg *sync.WaitGroup, vdb *database.VspDat
// Run voting wallet consistency check periodically.
wg.Add(1)
go func() {
ticker := time.NewTicker(consistencyInterval)
consistencyLoop:
for {
select {
case <-shutdownCtx.Done():
ticker.Stop()
break consistencyLoop
case <-ticker.C:
case <-time.After(consistencyInterval):
checkWalletConsistency()
}
}

View File

@ -202,19 +202,17 @@ func Open(ctx context.Context, shutdownWg *sync.WaitGroup, dbFile string, backup
return nil, fmt.Errorf("upgrade failed: %w", err)
}
// Start a ticker to update the backup file at the specified interval.
// Periodically update the database backup file.
shutdownWg.Add(1)
go func() {
ticker := time.NewTicker(backupInterval)
for {
select {
case <-ticker.C:
case <-time.After(backupInterval):
err := writeHotBackupFile(db)
if err != nil {
log.Errorf("Failed to write database backup: %v", err)
}
case <-ctx.Done():
ticker.Stop()
shutdownWg.Done()
return
}

View File

@ -159,7 +159,7 @@ func Start(ctx context.Context, requestShutdown func(), shutdownWg *sync.WaitGro
}
}()
// Use a ticker to update cached VSP stats.
// Periodically update cached VSP stats.
var refresh time.Duration
if s.cfg.Debug {
refresh = 1 * time.Second
@ -168,14 +168,12 @@ func Start(ctx context.Context, requestShutdown func(), shutdownWg *sync.WaitGro
}
shutdownWg.Add(1)
go func() {
ticker := time.NewTicker(refresh)
for {
select {
case <-ctx.Done():
ticker.Stop()
shutdownWg.Done()
return
case <-ticker.C:
case <-time.After(refresh):
err := updateCache(ctx, vdb, dcrd, config.NetParams, wallets)
if err != nil {
log.Errorf("Failed to update cached VSP stats: %v", err)