loops

package
v1.38.2 Latest Latest
Warning

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

Go to latest
Published: May 10, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrGracefulStop = errors.New("stop")

ErrGracefulStop is a special error, if returned from within loop function, will stop that loop without returning any error

Functions

func RunLoop

func RunLoop(ctx context.Context, interval time.Duration, fn func() error) (err error)

Loop runs a function in the loop with a consistent interval. If execution takes longer, the waiting time between iteration decreases. A single iteration has a deadline and cannot run longer than interval itself. There is a protection from panic which could crash adjacent loops.

Types

type ParanoidGroup

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

ParanoidGroup is a special primitive to run groups of goroutines, e.g. loops. If one of them fails (exits with an error), the wait group will unblock the flow, so the user has option to cancel the rest of routines or restart that single routine.

func (*ParanoidGroup) Go

func (p *ParanoidGroup) Go(fn func() error)

func (*ParanoidGroup) Initialized

func (p *ParanoidGroup) Initialized() bool

func (*ParanoidGroup) Wait

func (p *ParanoidGroup) Wait() error

Wait returns an error if one or more tasks failed, otherwise all tasks exited with no errors.

Jump to

Keyboard shortcuts

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