utils

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2019 License: MIT Imports: 11 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func After

func After(d time.Duration) *time.Time

After returns pointer to time after specific duration

func ExpandEnv

func ExpandEnv(
	args map[string]interface{},
	flag string,
	allowEmpty bool,
) string

func ExpandEnvUUID

func ExpandEnvUUID(
	args map[string]interface{},
	flag string,
) uuid.UUID

func GetSanitizedArgs

func GetSanitizedArgs() []string

func InSkipNamespace

func InSkipNamespace(skipNamespacePatterns []string, namespace string) bool

func MustParseDuration

func MustParseDuration(args map[string]interface{}, flag string) time.Duration

func MustParseInt

func MustParseInt(args map[string]interface{}, flag string) int

func SetLogger

func SetLogger(logger *log.Logger)

func Throttle

func Throttle(
	name string,
	interval time.Duration,
	tickLimit int32,
	fn func(args ...interface{})) func(args ...interface{},
)

func TruncateString

func TruncateString(str string, num int) string

func WithBackoff

func WithBackoff(fn func() error, backoff Backoff, logger *log.Logger) error

Types

type Backoff

type Backoff struct {
	Sleep      time.Duration
	MaxRetries int
}

type Ticker

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

func NewTicker

func NewTicker(name string, interval time.Duration, fn func(time.Time)) *Ticker

func (*Ticker) Start

func (ticker *Ticker) Start(immediate, async, block bool)

Start starts ticker. If immediate is true, the ticker tick immediately and blocks for this tick. If async is true, each tick firing will run in a different goroutine. Else, the tick in the same goroutine as the ticker itself. If block is true, Start will block the ticker forever. Else, the ticker will run in a different goroutine.

Note: when using async flag: 1. if it is true, you may need to apply needed synchronization between ticks. Also note that, ticks waiters may got a newer tick unlocking them.

2. if it is false, the ticker applies the needed synchronizations. In that case the ticker don't tick the next one unless the old tick finishes. So you may got inconsistent ticks intervals if a tick takes time larger than the tick interval to finish. So please consider timeouts if consistent ticks are needed.

func (*Ticker) WaitForNextTick

func (ticker *Ticker) WaitForNextTick() chan struct{}

WaitForNextTick returns a signal channel that gets unblocked after the next tick Example usage:

<- ticker.WaitForNextTick()

func (*Ticker) WaitForTick

func (ticker *Ticker) WaitForTick(tick time.Time) chan struct{}

Jump to

Keyboard shortcuts

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