Documentation
¶
Overview ¶
Package util holds small dependency-free helpers shared by all packages: the injected Clock, dependency checks, the Slot container and numeric helpers.
Index ¶
- func AlmostEqual(a, b, eps float64) bool
- func Clamp(v, lo, hi float64) float64
- func Midnight(t time.Time, loc *time.Location) time.Time
- func RequireAll(component string, deps ...Dep) error
- func Round(v float64, decimals int) float64
- func Sleep(ctx context.Context, c Clock, d time.Duration) error
- type Backoff
- type Clock
- type Dep
- type DependencyError
- type Slot
- type Ticker
- type Timer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AlmostEqual ¶
AlmostEqual reports whether a and b differ by at most eps.
func RequireAll ¶
RequireAll returns a *DependencyError listing every dependency that is nil, including typed nil pointers, maps, funcs, channels and interfaces stored in an interface.
Types ¶
type Backoff ¶
type Backoff struct {
Min, Max time.Duration
// Grace is the number of consecutive failures tolerated without a delay: a single
// dropped request should not hold back the next one.
Grace int
// contains filtered or unexported fields
}
Backoff tracks exponential reconnect delays (min → max, doubling) on an injected clock. It is owned by one goroutine and not safe for concurrent use.
func (*Backoff) Fail ¶
Fail records a failure at now and returns the delay until the next attempt (0 while within the grace).
type Clock ¶
type Clock interface {
Now() time.Time
NewTimer(d time.Duration) Timer
NewTicker(d time.Duration) Ticker
}
Clock is the only source of time in the pipeline. Production code gets the real clock, tests a clocktest.Clock that they advance by hand.
func NewRealClock ¶
func NewRealClock() Clock
NewRealClock returns the Clock backed by the system time.
type DependencyError ¶
DependencyError reports constructor dependencies that were nil.
func (*DependencyError) Error ¶
func (e *DependencyError) Error() string
type Slot ¶
type Slot[T any] struct { // contains filtered or unexported fields }
Slot holds the current instance of a value that is swapped at runtime, for example a component rebuilt by the supervisor while readers keep going through the slot.
func (*Slot[T]) ClearIf ¶
ClearIf removes the current value only while match reports it as the caller's own, so a late clear by a replaced instance never withdraws its successor.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package clocktest provides a manually driven util.Clock for tests: time only moves when the test calls Advance or Set, so polling, backoff and debounce run without sleeps.
|
Package clocktest provides a manually driven util.Clock for tests: time only moves when the test calls Advance or Set, so polling, backoff and debounce run without sleeps. |