clock

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2024 License: MIT Imports: 3 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
	NewTicker(d time.Duration) (<-chan time.Time, func())
	NewTimer(d time.Duration) (<-chan time.Time, func() bool)
	Since(t time.Time) time.Duration
}

Clock is a time abstraction which can be used to if you need to mock time in tests.

type MockClock

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

MockClock is a mock implementation of the Clock interface.

func NewMock

func NewMock(time time.Time) *MockClock

func (*MockClock) Add

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

Add advances the clock by the duration and triggers any timers or tickers that should fire.

func (*MockClock) NewTicker

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

NewTicker creates a new ticker that will fire once you advance the clock by the duration.

func (*MockClock) NewTimer

func (c *MockClock) NewTimer(d time.Duration) (<-chan time.Time, func() bool)

NewTimer creates a new timer that will fire once you advance the clock by the duration.

func (*MockClock) Now

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

Now returns the current time of the clock.

func (*MockClock) Set

func (c *MockClock) Set(t time.Time)

Set sets the time of the clock and triggers any timers or tickers that should fire.

func (*MockClock) Since

func (c *MockClock) Since(t time.Time) time.Duration

Since calculates the time since the given time t.

type RealClock

type RealClock struct{}

RealClock imlements the Clock interface using the standard libraries time package.

func New

func New() *RealClock

func (*RealClock) NewTicker

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

NewTicker is a wrapper around time.NewTicker().

func (*RealClock) NewTimer

func (c *RealClock) NewTimer(d time.Duration) (<-chan time.Time, func() bool)

NewTimer is a wrapper around time.NewTimer().

func (*RealClock) Now

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

Now is a wrapper around time.Now().

func (*RealClock) Since

func (c *RealClock) Since(t time.Time) time.Duration

Since is a wrapper around time.Since().

Jump to

Keyboard shortcuts

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