diff --git a/background/background.go b/background/background.go index f453143..92886f0 100644 --- a/background/background.go +++ b/background/background.go @@ -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() } } diff --git a/database/database.go b/database/database.go index e56cbf0..f319e2b 100644 --- a/database/database.go +++ b/database/database.go @@ -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 } diff --git a/webapi/webapi.go b/webapi/webapi.go index 7a35295..e5e29ec 100644 --- a/webapi/webapi.go +++ b/webapi/webapi.go @@ -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)