timing

package
v3.0.0-cursorPosition Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2021 License: Apache-2.0 Imports: 4 Imported by: 1

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. It should not be closed.
	ClearDelayCh = make(chan struct{})
)

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

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 FPSToFrameDelay

func FPSToFrameDelay(frameRate int) time.Duration

FPSToFrameDelay converts a frameRate like 60fps into a delay time between frames

func FPSToNano

func FPSToNano(fps float64) int64

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

func FrameDelayToFPS

func FrameDelayToFPS(dur time.Duration) float64

FrameDelayToFPS converts a duration of delay between frames into a frames per second count

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(tickDuration 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, successive 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