nowish

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2021 License: MIT Imports: 4 Imported by: 0

README

a simple Go library with useful time utiities:

  • Clock: a high performance clock giving a good "ish" representation of "now" (hence the name!)
  • Timeout: a reusable structure for enforcing timeouts with a cancel

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

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

func Start

func Start(precision time.Duration) (*Clock, func())

Start returns a new Clock instance initialized and started with the provided precision, along with the stop function for it's underlying timer

func (*Clock) Now

func (c *Clock) Now() time.Time

Now returns a good (ish) estimate of the current 'now' time

func (*Clock) NowFormat

func (c *Clock) NowFormat() string

NowFormat returns the formatted "now" time, cached until next tick and "now" updates

func (*Clock) SetFormat

func (c *Clock) SetFormat(format string)

SetFormat sets the time format string used by .NowFormat()

func (*Clock) Start

func (c *Clock) Start(precision time.Duration) func()

Start starts the clock with the provided precision, the returned function is the stop function for the underlying timer

type Timeout

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

Timeout provides a reusable structure for enforcing timeouts with a cancel

func NewTimeout

func NewTimeout() Timeout

NewTimeout returns a new Timeout instance

func (*Timeout) Cancel

func (t *Timeout) Cancel()

Cancel cancels the currently running timer. If a cancel is achieved, then this function will return after the timeout goroutine is finished

func (*Timeout) Start

func (t *Timeout) Start(d time.Duration, hook func())

Start starts the timer with supplied timeout. If timeout is reached before cancel then supplied timeout hook will be called. Error may be called if Timeout is already running when this function is called

Jump to

Keyboard shortcuts

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