timeutil

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2023 License: Apache-2.0, BSD-2-Clause Imports: 4 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanupTimer

func CleanupTimer(t *time.Timer)

CleanupTimer stops the timer and drains the Timer's channel. This cannot be done concurrent to other receives from the Timer's channel or other calls to the Timer's Stop method.

func Sleep

func Sleep(ctx context.Context, d time.Duration) bool

Sleep pauses the current goroutine for the duration d or until the context ctx is canceled. It returns whether Sleep paused for the entire duration or was canceled before that.

Types

type PrecisionTicker

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

PrecisionTicker is a ticker that can be used on systems (like windows) that do not offer a high enough time resolution for very fast ticker intervals.

func NewPrecisionTicker

func NewPrecisionTicker(callback func(), rate time.Duration, options ...PrecisionTickerOption) (precisionTicker *PrecisionTicker)

NewPrecisionTicker creates a new PrecisionTicker instance that executes the given callback function at the given rate.

func (*PrecisionTicker) Iterations

func (p *PrecisionTicker) Iterations() (iterations int)

Iterations returns the number of iterations that the ticker has performed.

func (*PrecisionTicker) Shutdown

func (p *PrecisionTicker) Shutdown()

Shutdown shuts down the ticker.

func (*PrecisionTicker) WaitForGracefulShutdown

func (p *PrecisionTicker) WaitForGracefulShutdown()

WaitForGracefulShutdown waits for the ticker to shut down gracefully.

func (*PrecisionTicker) WaitForShutdown

func (p *PrecisionTicker) WaitForShutdown()

WaitForShutdown waits for the ticker to shut down.

type PrecisionTickerOption

type PrecisionTickerOption func(*precisionTickerOptions)

PrecisionTickerOption is a function that can be used to configure a PrecisionTicker.

func WithMaxIterations

func WithMaxIterations(maxIterations int) PrecisionTickerOption

WithMaxIterations sets the maximum number of iterations that the ticker will perform.

func WithMinTimePrecision

func WithMinTimePrecision(minTimePrecision time.Duration) PrecisionTickerOption

WithMinTimePrecision sets the assumed minimum time precision of the system.

type Ticker

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

Ticker is task that gets executed repeatedly. It adjusts the intervals or drops ticks to make up for slow executions.

func NewTicker

func NewTicker(handler func(), interval time.Duration, ctx ...context.Context) (ticker *Ticker)

NewTicker creates a new Ticker from the given details. The interval must be greater than zero; if not, NewTicker will panic.

func (*Ticker) Shutdown

func (t *Ticker) Shutdown()

Shutdown shuts down the Ticker.

func (*Ticker) WaitForGracefulShutdown

func (t *Ticker) WaitForGracefulShutdown()

WaitForGracefulShutdown waits until the Ticker was shut down and the last handler has terminated.

func (*Ticker) WaitForShutdown

func (t *Ticker) WaitForShutdown()

WaitForShutdown waits until the Ticker was shut down.

Jump to

Keyboard shortcuts

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