Version: v0.0.0-...-5dc8409 Latest Latest

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

Go to latest
Published: Jan 28, 2018 License: Apache-2.0, MIT Imports: 3 Imported by: 0




This section is empty.


This section is empty.


This section is empty.


type Clock

type Clock interface {
	AfterFunc(d time.Duration, f func())
	Now() time.Time
	Sleep(d time.Duration)

Clock represents an interface to the functions in the standard library time package. Two implementations are available in the clock package. The first is a real-time clock which simply wraps the time package's functions. The second is a mock clock which will only make forward progress when programmatically adjusted.

func New

func New() Clock

New returns an instance of a real-time clock.

type Mock

type Mock struct {
	// contains filtered or unexported fields

Mock represents a mock clock that only moves forward programmically. It can be preferable to a real-time clock when testing time-based functionality.

func NewMock

func NewMock() *Mock

NewMock returns an instance of a mock clock. The current time of the mock clock on initialization is the Unix epoch.

func (*Mock) Add

func (m *Mock) Add(d time.Duration)

Add moves the current time of the mock clock forward by the duration. This should only be called from a single goroutine at a time.

func (*Mock) After

func (m *Mock) After(d time.Duration) <-chan time.Time

After produces a channel that will emit the time after a duration passes.

func (*Mock) AfterFunc

func (m *Mock) AfterFunc(d time.Duration, f func()) *Timer

AfterFunc waits for the duration to elapse and then executes a function. A Timer is returned that can be stopped.

func (*Mock) Now

func (m *Mock) Now() time.Time

Now returns the current wall time on the mock clock.

func (*Mock) Sleep

func (m *Mock) Sleep(d time.Duration)

Sleep pauses the goroutine for the given duration on the mock clock. The clock must be moved forward in a separate goroutine.

func (*Mock) Timer

func (m *Mock) Timer(d time.Duration) *Timer

Timer produces a timer that will emit a time some duration after now.

type Timer

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

Timer represents a single event.

func (*Timer) Next

func (t *Timer) Next() time.Time

func (*Timer) Tick

func (t *Timer) Tick()

type Timers

type Timers []*Timer

timers represents a list of sortable timers.

func (Timers) Len

func (ts Timers) Len() int

func (Timers) Less

func (ts Timers) Less(i, j int) bool

func (*Timers) Pop

func (ts *Timers) Pop() interface{}

func (*Timers) Push

func (ts *Timers) Push(t interface{})

func (Timers) Swap

func (ts Timers) Swap(i, j int)

Jump to

Keyboard shortcuts

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