timer

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2019 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SysSleepConsumer = func(d time.Duration) { time.Sleep(d) }

SysSleepConsumer is the default system sleep consumer

View Source
var SysTimeProvider = func() time.Time { return time.Now() }

SysTimeProvider is the default system time provider

Functions

This section is empty.

Types

type SleepConsumer

type SleepConsumer func(time.Duration)

SleepConsumer sleeps the given amount of time. This is usually the time.Sleep method, but can be something else for unit tests.

type TimeProvider

type TimeProvider func() time.Time

A TimeProvider returns the current time. This is usually the system time, but can be something else for unit tests.

func NewFixedTimeProviderFromNanoSeconds added in v0.25.0

func NewFixedTimeProviderFromNanoSeconds(timestamp int64) TimeProvider

NewFixedTimeProviderFromNanoSeconds creates a time provider from long nano seconds that always returns a fixed time

func NewFixedTimeProviderFromSeconds added in v0.25.0

func NewFixedTimeProviderFromSeconds(timestamp float64) TimeProvider

NewFixedTimeProviderFromSeconds creates a time provider from floating point seconds that always returns a fixed time

type Timer

type Timer struct {
	TimeProvider  TimeProvider
	SleepConsumer SleepConsumer
	// contains filtered or unexported fields
}

A Timer can be started and stopped. It will start at zero and count up, while running. It is event driven, there are now threads that update any state.

func NewTimer

func NewTimer() Timer

NewTimer creates a new stopped timer based on system time

func (*Timer) Delta

func (t *Timer) Delta() time.Duration

Delta returns the time since last call to Delta

func (*Timer) Elapsed

func (t *Timer) Elapsed() time.Duration

Elapsed returns the elapsed time of this timer

func (*Timer) Running

func (t *Timer) Running() bool

Running returns if timer is currently running

func (*Timer) Start

func (t *Timer) Start()

Start capturing the time

func (*Timer) Stop

func (t *Timer) Stop()

Stop capturing the time

func (*Timer) WaitTill

func (t *Timer) WaitTill(duration time.Duration)

WaitTill waits until the internal timer duration is reached.

func (*Timer) WaitTillNextFull added in v0.6.0

func (t *Timer) WaitTillNextFull(d time.Duration)

WaitTillNextFull waits until the internal timer has reached the next full given duration

func (*Timer) WaitTillNextFullSecond

func (t *Timer) WaitTillNextFullSecond()

WaitTillNextFullSecond waits until the internal timer has reached the next full second

Jump to

Keyboard shortcuts

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