Use time.After instead of tickers.
This commit is contained in:
parent
9fe6eb8e52
commit
c91ec5c697
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user