timecache

package
v0.0.0-...-0b2e9e9 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2020 License: BSD-2-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package timecache provides a cache for the system clock, to avoid calls to time.Now(). The time is stored as one int64 which holds the number of nanoseconds since the Unix Epoch. The value is accessed using atomic primitives, without locking. The package runs a global singleton TimeCache that is is updated every second.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Now

func Now() time.Time

Now calls Now on the global TimeCache instance.

func NowUnix

func NowUnix() int64

NowUnix calls NowUnix on the global TimeCache instance.

func NowUnixNano

func NowUnixNano() int64

NowUnixNano calls NowUnixNano on the global TimeCache instance.

Types

type TimeCache

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

A TimeCache is a cache for the current system time. The cached time has nanosecond precision.

func New

func New() *TimeCache

New returns a new TimeCache instance. The TimeCache must be started to update the time.

func (*TimeCache) Now

func (t *TimeCache) Now() time.Time

Now returns the cached time as a time.Time value.

func (*TimeCache) NowUnix

func (t *TimeCache) NowUnix() int64

NowUnix returns the cached time as seconds since the Unix Epoch.

func (*TimeCache) NowUnixNano

func (t *TimeCache) NowUnixNano() int64

NowUnixNano returns the cached time as nanoseconds since the Unix Epoch.

func (*TimeCache) Run

func (t *TimeCache) Run(interval time.Duration)

Run runs the TimeCache, updating the cached clock value once every interval and blocks until Stop is called.

func (*TimeCache) Stop

func (t *TimeCache) Stop()

Stop stops the TimeCache. The cached time remains valid but will not be updated anymore. A TimeCache can not be restarted. Construct a new one instead. Calling Stop again is a no-op.

Jump to

Keyboard shortcuts

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