inctimer

package
v0.0.0-...-36c81cc Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func After

func After(d time.Duration) <-chan time.Time

After wraps the time.After function to get around the customvet warning for cases where it is inconvenient to use the instantiated version.

Types

type IncTimer

type IncTimer interface {
	After(time.Duration) <-chan time.Time
}

IncTimer should be the preferred mechanism over calling `time.After` when wanting an `After`-like function in a loop. This prevents memory build up as the `time.After` method creates a new timer instance every time it is called, and it is not garbage collected until after it fires. Conversely, IncTimer only uses one timer and correctly stops the timer, clears its channel, and resets it everytime that `After` is called.

func New

func New() (IncTimer, func() bool)

New creates a new IncTimer and a done function. IncTimer only uses one timer and correctly stops the timer, clears the channel, and resets it every time the `After` function is called. WARNING: Concurrent use is not expected. The use of this timer should be for only one goroutine.

Jump to

Keyboard shortcuts

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