timing

package
v2.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package timing provides utilities for time

Index

Constants

This section is empty.

Variables

View Source
var (
	// ClearDelayCh is used to stop all ongoing delays
	ClearDelayCh = make(chan bool)
)

Functions

func DoAfter

func DoAfter(d time.Duration, f func())

DoAfter wraps time calls in a select that will stop events from happening when ClearDelayCh pulls

func DoAfterContext added in v2.4.0

func DoAfterContext(ctx context.Context, f func())

DoAfterContext executes the function if the context is completed. Clears out if the Delay Channel is cleared.

func FPS

func FPS(lastTime, now time.Time) float64

FPS returns the number of frames being processed per second, supposing a time interval from lastTime to now.

func FPSToDuration

func FPSToDuration(frameRate int) time.Duration

FPSToDuration converts a frameRate like 60fps into a duration

func FPSToNano

func FPSToNano(fps float64) int64

FPSToNano converts a framesPerSecond value to the number of nanoseconds that should take place for each frame.

Types

type DynamicTicker

type DynamicTicker struct {
	C chan time.Time
	// contains filtered or unexported fields
}

A DynamicTicker is a ticker which can be sent signals in the form of durations to change how often it ticks.

func NewDynamicTicker

func NewDynamicTicker() *DynamicTicker

NewDynamicTicker returns a null-initialized dynamic ticker

func (*DynamicTicker) ForceStep

func (dt *DynamicTicker) ForceStep()

ForceStep is the blocking equivalent to Step. After this is called, it won't return until the ticker has taken the forced step through. A potential use for this is in benchmarking how often the work between ticks can get done.

func (*DynamicTicker) SetTick

func (dt *DynamicTicker) SetTick(d time.Duration)

SetTick changes the rate at which a dynamic ticker ticks

func (*DynamicTicker) Step

func (dt *DynamicTicker) Step()

Step will force the dynamic ticker to tick, once. If the forced tick is not received, multiple calls to step will do nothing.

func (*DynamicTicker) Stop

func (dt *DynamicTicker) Stop()

Stop closes all internal channels and stops dt's internal ticker

Jump to

Keyboard shortcuts

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