tk

package
v1.1.29 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TimeFn

func TimeFn[T any](name string, fn func() T) T

TimeFn wraps a function with timing because knowing how long things take is occasionally useful

Types

type AsyncTimeKeeper

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

AsyncTimeKeeper tracks concurrent operations because parallel timing is twice the fun

func NewAsyncTimeKeeper

func NewAsyncTimeKeeper(name string) *AsyncTimeKeeper

NewAsyncTimeKeeper creates a new async timekeeper because concurrent timing needs special handling

func (*AsyncTimeKeeper) Track

func (atk *AsyncTimeKeeper) Track(fn func())

Track adds a new operation to track because keeping track of parallel operations is like herding cats

func (*AsyncTimeKeeper) Wait

func (atk *AsyncTimeKeeper) Wait() []time.Duration

Wait waits for all operations to complete because patience is still a virtue

type TimeKeeper

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

TimeKeeper tracks execution time because time is money, and we're all about that ROI

func NewTimeKeeper

func NewTimeKeeper(name string, opts ...TimeKeeperOption) *TimeKeeper

NewTimeKeeper creates a new timekeeper because someone has to watch the clock

func (*TimeKeeper) Start

func (tk *TimeKeeper) Start() *TimeKeeper

Start begins timing because every journey begins with a single step

func (*TimeKeeper) Stop

func (tk *TimeKeeper) Stop() time.Duration

Stop ends timing and logs the duration because all good things must come to an end

type TimeKeeperOption

type TimeKeeperOption func(*TimeKeeper)

func WithCallback

func WithCallback(cb func(duration time.Duration)) TimeKeeperOption

WithCallback adds a callback function because sometimes you want to do more than just log

Jump to

Keyboard shortcuts

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