utils

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 6, 2025 License: MIT Imports: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseError

type BaseError struct {
	// contains filtered or unexported fields
}

BaseError is a simple wrapper that implements the error interface and allows attaching additional context to errors returned by the library.

func NewBaseError

func NewBaseError(wrapped error, msg string, args ...any) *BaseError

NewBaseError creates a new BaseError that wraps an underlying error with a formatted message.

func (*BaseError) Error

func (be *BaseError) Error() string

func (*BaseError) Unwrap

func (be *BaseError) Unwrap() error

type Clock

type Clock struct{}

Clock implements IClock using the real time package.

func NewRealClock

func NewRealClock() *Clock

NewRealClock returns a Clock that uses the system clock.

func (*Clock) Now

func (c *Clock) Now() time.Time

Now returns the current time.

func (*Clock) Sleep

func (c *Clock) Sleep(duration time.Duration)

Sleep pauses for the specified duration.

type IClock

type IClock interface {
	// Get the current time
	Now() time.Time
	// Sleep for the given duration
	Sleep(duration time.Duration)
}

IClock abstracts time functions so that the tracker can be tested with custom clocks. It can be implemented using a mock clock to run simulations.

type ITicker

type ITicker interface {
	C() <-chan time.Time
	Stop()
}

ITicker abstracts a time.Ticker so that time can be controlled in tests.

type Ticker

type Ticker struct {
	// contains filtered or unexported fields
}

Ticker wraps time.Ticker to satisfy the ITicker interface.

func NewRealTicker

func NewRealTicker(duration time.Duration) *Ticker

NewRealTicker creates a ticker that ticks at the specified duration.

func (*Ticker) C

func (t *Ticker) C() <-chan time.Time

C returns the underlying ticker's channel.

func (*Ticker) Stop

func (t *Ticker) Stop()

Stop stops the ticker.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL