clock

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 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 Clock

type Clock interface {
	Now() time.Time
	After(time.Duration) <-chan time.Time
	AfterFunc(time.Duration, func()) *Timer
	Sleep(time.Duration)
	NewTicker(time.Duration) *Ticker
	NewTimer(time.Duration) *Timer
}

Clock provides time controls for production and tests.

func New

func New() Clock

New returns a system-backed clock.

type MockClock

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

MockClock is a controllable clock for tests.

func NewMock

func NewMock() *MockClock

NewMock returns a controllable mock clock.

func (*MockClock) Add

func (c *MockClock) Add(d time.Duration)

Add advances the mock clock.

func (*MockClock) After

func (c *MockClock) After(d time.Duration) <-chan time.Time

After returns a channel that fires after the duration.

func (*MockClock) AfterFunc

func (c *MockClock) AfterFunc(d time.Duration, f func()) *Timer

AfterFunc waits for the duration then invokes f.

func (*MockClock) NewTicker

func (c *MockClock) NewTicker(d time.Duration) *Ticker

NewTicker returns a ticker.

func (*MockClock) NewTimer

func (c *MockClock) NewTimer(d time.Duration) *Timer

NewTimer returns a timer.

func (*MockClock) Now

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

Now returns the current mock time.

func (*MockClock) Sleep

func (c *MockClock) Sleep(d time.Duration)

Sleep blocks for the duration in mock time.

type RealClock

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

RealClock uses the system clock.

func (*RealClock) After

func (c *RealClock) After(d time.Duration) <-chan time.Time

After waits for the duration and returns a channel.

func (*RealClock) AfterFunc

func (c *RealClock) AfterFunc(d time.Duration, f func()) *Timer

AfterFunc waits for the duration then invokes f.

func (*RealClock) NewTicker

func (c *RealClock) NewTicker(d time.Duration) *Ticker

NewTicker returns a ticker.

func (*RealClock) NewTimer

func (c *RealClock) NewTimer(d time.Duration) *Timer

NewTimer returns a timer.

func (*RealClock) Now

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

Now returns the current time.

func (*RealClock) Sleep

func (c *RealClock) Sleep(d time.Duration)

Sleep blocks for the duration.

type Ticker

type Ticker struct {
	C <-chan time.Time
	// contains filtered or unexported fields
}

Ticker wraps a clock ticker with a channel and controls.

func (*Ticker) Reset

func (t *Ticker) Reset(d time.Duration)

Reset resets the ticker to the new duration.

func (*Ticker) Stop

func (t *Ticker) Stop()

Stop stops the ticker.

type Timer

type Timer struct {
	C <-chan time.Time
	// contains filtered or unexported fields
}

Timer wraps a clock timer with a channel and stop/reset controls.

func (*Timer) Reset

func (t *Timer) Reset(d time.Duration) bool

Reset resets the timer to the new duration.

func (*Timer) Stop

func (t *Timer) Stop() bool

Stop stops the timer.

Jump to

Keyboard shortcuts

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