clock

package
v0.10.0-beta Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2020 License: MIT Imports: 2 Imported by: 32 modules, 81 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 local time (as defined by the Clock).
	Now() time.Time

	// TickAfter returns a channel that will receive a tick after the specified
	// duration has passed.
	TickAfter(duration time.Duration) <-chan time.Time
}

Clock is an interface that provides a time functions for LND packages. This is useful during testing when a concrete time reference is needed.

func NewDefaultClock

func NewDefaultClock() Clock

NewDefaultClock constructs a new DefaultClock.

type DefaultClock

type DefaultClock struct{}

DefaultClock implements Clock interface by simply calling the appropriate time functions.

func (DefaultClock) Now

func (DefaultClock) Now() time.Time

Now simply returns time.Now().

func (DefaultClock) TickAfter

func (DefaultClock) TickAfter(duration time.Duration) <-chan time.Time

TickAfter simply wraps time.After().

type TestClock

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

TestClock can be used in tests to mock time.

func NewTestClock

func NewTestClock(startTime time.Time) *TestClock

NewTestClock returns a new test clock.

func (*TestClock) Now

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

Now returns the current (test) time.

func (*TestClock) SetTime

func (c *TestClock) SetTime(now time.Time)

SetTime sets the (test) time and triggers tick channels when they expire.

func (*TestClock) TickAfter

func (c *TestClock) TickAfter(duration time.Duration) <-chan time.Time

TickAfter returns a channel that will receive a tick after the specified duration has passed passed by the user set test time.

Jump to

Keyboard shortcuts

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