Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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, logger zerolog.Logger, 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.