-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I was going through trying to refactor the demo project to use `rivershared`, and while doing so, noticed that it'd broken out some of the `BaseService` functions like `CancellableSleep` into a new package so that they could be used without an available `BaseService`. Looking over this API again, there's no good reason for functions like `CancellableSleep` and `ExponentialBackoff` to be tied so tight to `BaseService`. The reason they are is that `BaseService` provides a random 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 old `math/rand` seeding problem. A single random source is initialized and seeding 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 top level functions. Once we drop support for Go 1.21, we'll be able to simplify this code dramatically by dropping `BaseService.Rand` and the random source arguments from functions like `ExponentialBackoff` in favor of just using top level `math/rand/v2` functions. I also drop the variant `CancellableSleepBetween` in favor of having callers use `CancellableSleep` combined with `randutil.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.
- Loading branch information
Showing
18 changed files
with
251 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.