clock

package
Version: v0.0.0-...-0e1f9d6 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2021 License: Apache-2.0 Imports: 1 Imported by: 114

README

Clock

This package provides an interface for time-based operations. It allows mocking time for testing.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

type Clock interface {
	PassiveClock
	After(d time.Duration) <-chan time.Time
	NewTimer(d time.Duration) Timer
	Sleep(d time.Duration)
	Tick(d time.Duration) <-chan time.Time
}

Clock allows for injecting fake or real clocks into code that needs to do arbitrary things based on time.

type PassiveClock

type PassiveClock interface {
	Now() time.Time
	Since(time.Time) time.Duration
}

PassiveClock allows for injecting fake or real clocks into code that needs to read the current time but does not support scheduling activity in the future.

type RealClock

type RealClock struct{}

RealClock really calls time.Now()

func (RealClock) After

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

After is the same as time.After(d).

func (RealClock) NewTimer

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

NewTimer is the same as time.NewTimer(d)

func (RealClock) Now

func (RealClock) Now() time.Time

Now returns the current time.

func (RealClock) Since

func (RealClock) Since(ts time.Time) time.Duration

Since returns time since the specified timestamp.

func (RealClock) Sleep

func (RealClock) Sleep(d time.Duration)

Sleep is the same as time.Sleep(d)

func (RealClock) Tick

func (RealClock) Tick(d time.Duration) <-chan time.Time

Tick is the same as time.Tick(d)

type Timer

type Timer interface {
	C() <-chan time.Time
	Stop() bool
	Reset(d time.Duration) bool
}

Timer allows for injecting fake or real timers into code that needs to do arbitrary things based on time.

Source Files

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to