clock

package module
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2021 License: MIT Imports: 2 Imported by: 1

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 NewTestClockWithTickSignal

func NewTestClockWithTickSignal(startTime time.Time,
	tickSignal chan time.Duration) *TestClock

NewTestClockWithTickSignal will create a new test clock with an added channel which will be used to signal when a new ticker is registered. This is useful when creating a ticker on a separate goroutine and we'd like to wait for that to happen before advancing the test case.

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