netTime

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2023 License: BSD-2-Clause Imports: 2 Imported by: 95

Documentation

Overview

Package netTime provides a custom time function that should provide the current accurate time used by the network from a custom time service.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func After

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

After waits for the duration to elapse and then sends the current time on the returned channel. It is equivalent to NewTimer(d).C. Refer to time.After for more information.

func SetOffset

func SetOffset(timeToOffset time.Duration)

SetOffset sets the internal offset variable atomically. All calls to Now will have this offset added to the result. Negative offsets are accepted and will reduce the result of the call to Now.

func SetTimeSource

func SetTimeSource(nowFunc TimeSource)

SetTimeSource sets Now to a custom source. All calls to Now will use this TimeSource. Note that this is in-memory, so any restart will require that this function be recalled.

func Since

func Since(t time.Time) time.Duration

Since returns the time elapsed since t. It is shorthand for:

netTime.Now().Sub(t).

func Until

func Until(t time.Time) time.Duration

Until returns the duration until t. It is shorthand for:

t.Sub(netTime.Now()).

Types

type NowFunc

type NowFunc func() time.Time

NowFunc is defined as the function interface for time.Now.

var Now NowFunc = time.Now

Now returns the current accurate time. The function must be set an accurate time service that returns the current time with an accuracy of +/- 300 ms.

type TimeSource

type TimeSource interface {
	NowMs() int64
}

TimeSource is an interface which matches a time service that may be used to set Now.

type Timer

type Timer struct {
	*time.Timer
}

The Timer type represents a single event. When the Timer expires, the current time will be sent on C, unless the Timer was created by AfterFunc. A Timer must be created with NewTimer or AfterFunc.

func AfterFunc

func AfterFunc(d time.Duration, f func()) *Timer

AfterFunc waits for the duration to elapse and then calls f in its own goroutine. It returns a Timer that can be used to cancel the call using its Stop method. Refer to time.AfterFunc for more information.

func NewTimer

func NewTimer(d time.Duration) *Timer

NewTimer creates a new Timer that will send the current time on its channel after at least duration d. This wraps a time.Timer to provide a timer accurate to the set time source.

func (*Timer) Reset

func (t *Timer) Reset(d time.Duration) bool

Reset changes the timer to expire after duration d. It returns true if the timer had been active, false if the timer had expired or been stopped. Refer to time/Timer.Reset for more information.

Jump to

Keyboard shortcuts

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