-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add support for context.Context
in Retry
#5
Conversation
Existing function `Retry` is maintained with the same API to preserve backwards compatibility. New function `RetryWithContext` accepts a context and delivers it to the retryable function. Each retry attempt can be limited by timeout (via context, `WithAttemptTimeout`). Garbage-collected channel `C` which wasn't used. Replaced stop channel delivery with `close(ch)` to avoid having a channel with a single entry. Removed `time.After()` as it leaks the object until timer fires. Fixes siderolabs#2 Signed-off-by: Andrey Smirnov <[email protected]>
/approve |
@@ -138,7 +146,7 @@ func (t ticker) StopChan() <-chan struct{} { | |||
} | |||
|
|||
func (t ticker) Stop() { | |||
t.s <- struct{}{} | |||
close(t.s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if that should be wrapped with sync.Once
to allow several Stop()
calls like time.Ticker
allows
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think sync.Once
is pretty heavyweight, I don't think we even ever used .Stop()
in our codebase (never saw it myself, but still could be used somewhere).
Probably even .Stop()
is no longer required given that we have a context which can be canceled (but that is not backwards compatible).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so, I would rather not do it unless we see a big use case for .Stop()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, makes sense
/lgtm |
Existing function
Retry
is maintained with the same API to preservebackwards compatibility.
New function
RetryWithContext
accepts a context and delivers it to theretryable function. Each retry attempt can be limited by timeout (via
context,
WithAttemptTimeout
).Garbage-collected channel
C
which wasn't used.Replaced stop channel delivery with
close(ch)
to avoid having achannel with a single entry.
Removed
time.After()
as it leaks the object until timer fires.Fixes #2
Signed-off-by: Andrey Smirnov [email protected]