clock

package
v0.10.0-beta.rc6 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: 58

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