tasks

package
v0.0.0-...-c859c3e Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2024 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecWithInterval

func ExecWithInterval(fn StoppableFunc, start, limit time.Duration)

ExecWithInterval executes a function with a dynamic interval the interval is getting multiplied by 2 in each round, up to the given limit and then it starts all over 1s > 2s > 4s > 8s ... > 1s > 2s > ...

func ExecWithTimeout

func ExecWithTimeout(ctx context.Context, fn Func, t time.Duration) (bool, interface{}, error)

ExecWithTimeout triggers some function in the given time frame, returns true if completed

func NewExecutionQueue

func NewExecutionQueue(interval time.Duration, opt ...ExecQueueOpt) queue.Queue

NewExecutionQueue creates a new instance

func Retry

func Retry(fn Fn, retries int) error

Retry executes a function x times or until successful

func RetryWithContext

func RetryWithContext(pctx context.Context, fn Fn, retries int) error

RetryWithContext executes a function x times or until successful

Types

type ExecQueueOpt

type ExecQueueOpt func(*executionQueue)

ExecQueueOpt enables to inject more parameters

func WithoutErrors

func WithoutErrors() ExecQueueOpt

WithoutErrors disables errors

type Fn

type Fn = queue.Fn

Fn represents a function to execute

type Func

type Func = func(stopper Stopper) (interface{}, error)

Func is the interface of functions to trigger

type StoppableFunc

type StoppableFunc func(lastTick time.Duration) (stop bool, cont bool)

StoppableFunc represents a function that returns two boolean to help with its execution stop will stop the interval, while continue will make the interval value to remain the same if both are false, the interval will be increased (x2)

type Stopper

type Stopper interface {
	// IsStopped returns true if the stopper already stopped
	IsStopped() bool
}

Stopper represents the object used to stop running functions should be used by the running function, once stopped the function act accordingly

Jump to

Keyboard shortcuts

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