Break BaseService
functions into serviceutil
#536
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I was going through trying to refactor the demo project to use
rivershared
, and while doing so, noticed that it'd broken out someof the
BaseService
functions likeCancellableSleep
into a newpackage so that they could be used without an available
BaseService
.Looking over this API again, there's no good reason for functions like
CancellableSleep
andExponentialBackoff
to be tied so tight toBaseService
. The reason they are is thatBaseService
provides arandom source that both can conveniently use, but that can be moved to a
function argument instead.
The reason that
BaseService
has a random source is to avoid the oldmath/rand
seeding problem. A single random source is initialized andseeding securely once, then placed onto an archetype that's inherited
by all
BaseService
instances.Soon, even that can go away. One of the biggest things fixed by Go
1.22's
math/rand/v2
is that it's no longer necessary to seed the toplevel functions. Once we drop support for Go 1.21, we'll be able to
simplify this code dramatically by dropping
BaseService.Rand
and therandom source arguments from functions like
ExponentialBackoff
infavor of just using top level
math/rand/v2
functions.I also drop the variant
CancellableSleepBetween
in favor of havingcallers use
CancellableSleep
combined withrandutil.DurationBetween
,a new random helper similar to
IntBetween
.With all this in, we'll be able to fully jettison all utilities from the
demo project in favor of going all in with
rivershared
's equivalents.