Skip to content

Commit c8546d9

Browse files
authored
Merge pull request #884 from bhandras/notification-no-busy-wait
notifications: do not hog the CPU if there's no L402 token yet
2 parents 992884c + 0591a94 commit c8546d9

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

notifications/manager.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,17 @@ func (m *Manager) Run(ctx context.Context) error {
149149
waitTime time.Duration
150150
backoff time.Duration
151151
attempts int
152+
timer = time.NewTimer(0)
152153
)
153154

154155
// Start the notification runloop.
155156
for {
156157
// Increase the wait time for the next iteration.
157158
backoff = waitTime + time.Duration(attempts)*time.Second
158159
waitTime = 0
159-
timer := time.NewTimer(backoff)
160+
161+
// Reset the timer with the new backoff time.
162+
timer.Reset(backoff)
160163

161164
// Return if the context has been canceled.
162165
select {
@@ -179,6 +182,10 @@ func (m *Manager) Run(ctx context.Context) error {
179182
log.Errorf("Error getting L402 from "+
180183
"the store: %v", err)
181184
}
185+
186+
// Use a default of 1 second wait time to avoid
187+
// hogging the CPU.
188+
waitTime = time.Second
182189
continue
183190
}
184191

0 commit comments

Comments
 (0)