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: 0

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