Documentation ¶
Index ¶
- func FreePort() (int, error)
- func NewChannelWithWorkerPool(ctx context.Context, numWorkers, channelLen int, env adapter.Env, ...) chan WorkFunc
- func NewReservoir(env adapter.Env, limit int) (chan<- interface{}, <-chan interface{}, <-chan interface{})
- func ReadPropertiesFile(fileName string) (map[string]string, error)
- func SprintfRedacts(redacts []interface{}, format string, a ...interface{}) string
- func Truncate(in string, end int) string
- type AtomicBool
- type Backoff
- type ErrorFunc
- type ExponentialBackoff
- type Looper
- type WorkFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewChannelWithWorkerPool ¶
func NewChannelWithWorkerPool(ctx context.Context, numWorkers, channelLen int, env adapter.Env, errHandler ErrorFunc, backoff Backoff) chan WorkFunc
NewChannelWithWorkerPool returns an unbuffered channel to send work to and the set of workers. Close the returned channel or cancel the Context and the workers will exit. Passed ctx is passed on to the work function and work should check for cancel if long-running. Beware: If errHandler itself returns an error, the worker will exit.
func NewReservoir ¶
func NewReservoir(env adapter.Env, limit int) (chan<- interface{}, <-chan interface{}, <-chan interface{})
NewReservoir sends from one channel to another without blocking until closed. Once "in" channel is closed, "out" will continue to drain before closing. if buffer limit is reached, new messages (LIFO) are sent to overflow: non-blocking, can be overrun.
func ReadPropertiesFile ¶
ReadPropertiesFile Parses a simple properties file (xx=xx format)
func SprintfRedacts ¶
SprintfRedacts truncates secret strings to len(5)
Types ¶
type AtomicBool ¶
type AtomicBool struct {
// contains filtered or unexported fields
}
AtomicBool is a threadsafe bool
func (*AtomicBool) SetFalse ¶
func (a *AtomicBool) SetFalse() bool
SetFalse sets the bool to false, returns true if unchanged
func (*AtomicBool) SetTrue ¶
func (a *AtomicBool) SetTrue() bool
SetTrue sets the bool to true, returns true if unchanged
type Backoff ¶
Backoff defines functions for RPC Backoff strategy.
func DefaultExponentialBackoff ¶
func DefaultExponentialBackoff() Backoff
DefaultExponentialBackoff constructs a new ExponentialBackoff with defaults.
type ErrorFunc ¶
ErrorFunc handles errors
func LogErrorsHandler ¶
LogErrorsHandler just logs errors and continues
type ExponentialBackoff ¶
type ExponentialBackoff struct {
// contains filtered or unexported fields
}
ExponentialBackoff is a backoff strategy that backs off exponentially.
func (*ExponentialBackoff) Attempt ¶
func (b *ExponentialBackoff) Attempt() int
Attempt returns how many attempts have been made.
func (*ExponentialBackoff) Clone ¶
func (b *ExponentialBackoff) Clone() Backoff
Clone returns a copy
func (*ExponentialBackoff) Duration ¶
func (b *ExponentialBackoff) Duration() time.Duration
Duration calculates how long should be waited before attempting again. Note that this method is stateful - each call counts as an "attempt".
func (*ExponentialBackoff) Reset ¶
func (b *ExponentialBackoff) Reset()
Reset clears any state that the backoff strategy has.
type Looper ¶
Looper provides for Backoff and cancellation
func (*Looper) Chan ¶
Chan pulls work from work channel until channel is closed of Context canceled. Passed ctx is passed on to the work function and work should check for cancel if long-running. If errHandler itself returns an error, the daemon will exit.
func (*Looper) Run ¶
Run the work until successful (or ctx canceled) with backoff. Passed ctx should be cancelable - to exit, cancel the Context. Passed ctx is passed on to the work function and work should check for cancel if long-running. If errHandler itself returns an error, the daemon will exit.
func (*Looper) Start ¶
func (l *Looper) Start(ctx context.Context, work WorkFunc, period time.Duration, errHandler ErrorFunc)
Start a daemon that repeatedly calls work function according to period. Passed ctx should be cancelable - to exit, cancel the Context. Passed ctx is passed on to the work function and work should check for cancel if long-running. If errHandler itself returns an error, the daemon will exit.