clock

package
v0.0.0-...-967d409 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 1 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

type Clock interface {
	// Now returns the current time, as defined by this Clock.
	Now() time.Time

	// NewTimer creates a new Timer associated with this Clock.
	NewTimer(d time.Duration) Timer

	// NewTimerAt creates a new Timer that fires at or after the given time.
	NewTimerAt(at time.Time) Timer
}

Clock is a simple interface that returns a "current" timestamp. This will generally be the current time, but the Clock interface can be mocked during testing to make testing time-sensitive components deterministic.

func NewClock

func NewClock() Clock

NewClock creates a new Clock instance that returns the current time.

type Timer

type Timer interface {

	// GetC returns this Timer's signal channel. For real clocks, this simply returns a time.Timer.C.
	GetC() <-chan time.Time

	// Stop stops the timer. Like time.Timer.Stop(), it returns true if the call stops the timer,
	// false if the timer has already expired or been stopped. See documentation for time.Timer.Stop()
	// for more information about this method's behavior.
	Stop() bool
}

Timer mimics a time.Timer, providing a channel that delivers a signal after a certain amount of time has elapsed. When associated with a MockClock, Timer delivers its signal when the MockClock's time is programmatically set to a certain point.

func NewStoppedTimer

func NewStoppedTimer() Timer

NewStoppedTimer creates a Timer that will never fire.

Jump to

Keyboard shortcuts

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