Skip to content

Commit

Permalink
Merge pull request #884 from bhandras/notification-no-busy-wait
Browse files Browse the repository at this point in the history
notifications: do not hog the CPU if there's no L402 token yet
  • Loading branch information
bhandras authored Feb 7, 2025
2 parents 992884c + 0591a94 commit c8546d9
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion notifications/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,17 @@ func (m *Manager) Run(ctx context.Context) error {
waitTime time.Duration
backoff time.Duration
attempts int
timer = time.NewTimer(0)
)

// Start the notification runloop.
for {
// Increase the wait time for the next iteration.
backoff = waitTime + time.Duration(attempts)*time.Second
waitTime = 0
timer := time.NewTimer(backoff)

// Reset the timer with the new backoff time.
timer.Reset(backoff)

// Return if the context has been canceled.
select {
Expand All @@ -179,6 +182,10 @@ func (m *Manager) Run(ctx context.Context) error {
log.Errorf("Error getting L402 from "+
"the store: %v", err)
}

// Use a default of 1 second wait time to avoid
// hogging the CPU.
waitTime = time.Second
continue
}

Expand Down

0 comments on commit c8546d9

Please sign in to comment.