clock

package
v0.0.0-...-bbc9ce3 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2021 License: BSD-2-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package clock provides a mockable wrapper for `time.Now()`.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func After

func After(ctx context.Context, d time.Duration) <-chan time.Time

After returns time.After() or the equivalent for the clock associated with the given context.

func NewContext

func NewContext(ctx context.Context, c clock) context.Context

NewContext returns a new context with the given clock attached.

This should generally only be used in tests; production code should always use the real time.

func Now

func Now(ctx context.Context) time.Time

Now returns the current time for the clock associated with the given context, or the real current time if there is no clock associated with the context. Any code that needs to be tested with a mocked-out time should use `clock.Now()` instead of `time.Now()`.

Types

type FakeClock

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

FakeClock provides support for mocking the current time in tests.

func NewFakeClock

func NewFakeClock() *FakeClock

func (*FakeClock) Advance

func (c *FakeClock) Advance(d time.Duration)

func (*FakeClock) After

func (c *FakeClock) After(d time.Duration) <-chan time.Time

func (*FakeClock) AfterCalledChan

func (c *FakeClock) AfterCalledChan() <-chan struct{}

AfterCalledChan returns the channel to wait for the clock's timer to be set from a call to After().

func (*FakeClock) Now

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

Jump to

Keyboard shortcuts

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