You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is because you didn't subclass JitterBackoff from SimpleBackoff (i.e. embedded it inside), but just defined it as a type alias. However, this is not really an alias, and go considers this as a new type. Because of this, this does not make the original Reset() apply to JitterBackoff as well. Thus, go complains that no Reset() implementation exists for the new JitterBackoff type.
Since the only difference I see between these two structs is a single line in NextAttempt() (the one that adds jitter), my best solution to this is to refactor your code a bit:
Make a single Backoff type, no need for two simple and jitter types.
Add to it an extra jitter bool member.
Create a NewSimpleBackoff() and NewJitterBackoff() functions. Where NewSimpleBackoff() returns a new Backoff instance with jitter set to false. NewJitterBackoff would set it to true.
Implement NextAttempt() only once, and check for jitter's value to decide whether to add jitter or not.
Pros for this:
Using NewX() init functions, which is a go idiom for creating instances, and is strict about the arguments it receives, being able to check for valid function arguments. Asking for the user to just init a new struct themselves (e.g. b := &goback.JitterBackof{..}) is dangerous. It took me 15 minutes just to scan your source and make sure I'm setting all values right, and understand that I shouldn't touch the publicAttempts member.
Cut back on lines of code, and a simple code structure - you only have a single type (Backoff) and not two (Simple, Jitter).
You get to fix this bug I've originally opened this issue for. :)
Keep up the good work!
The text was updated successfully, but these errors were encountered:
First of all, great project! It's a much simpler way of doing things compared to https://github.com/eapache/go-resiliency. 👍
I'm getting this compilation error when using
JitterBackoff
:This is because you didn't subclass
JitterBackoff
fromSimpleBackoff
(i.e. embedded it inside), but just defined it as a type alias. However, this is not really an alias, and go considers this as a new type. Because of this, this does not make the originalReset()
apply toJitterBackoff
as well. Thus, go complains that noReset()
implementation exists for the newJitterBackoff
type.Since the only difference I see between these two structs is a single line in
NextAttempt()
(the one that adds jitter), my best solution to this is to refactor your code a bit:Backoff
type, no need for two simple and jitter types.jitter bool
member.NewSimpleBackoff()
andNewJitterBackoff()
functions. WhereNewSimpleBackoff()
returns a newBackoff
instance withjitter
set tofalse
.NewJitterBackoff
would set it totrue
.NextAttempt()
only once, and check forjitter
's value to decide whether to add jitter or not.Pros for this:
NewX()
init functions, which is a go idiom for creating instances, and is strict about the arguments it receives, being able to check for valid function arguments. Asking for the user to just init a new struct themselves (e.g.b := &goback.JitterBackof{..}
) is dangerous. It took me 15 minutes just to scan your source and make sure I'm setting all values right, and understand that I shouldn't touch the publicAttempts
member.Backoff
) and not two (Simple
,Jitter
).Keep up the good work!
The text was updated successfully, but these errors were encountered: