common

package
v0.1.65 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultVal

func DefaultVal[T comparable](val, def T) T

func KeysFromItems

func KeysFromItems[T any](items *[]T, getKey func(T) int64) []int64

KeysFromItems returns the int64 keys from a response Items field.

Types

type BackoffConfig

type BackoffConfig struct {
	Strategy     BackoffStrategy `mapstructure:"strategy" json:"strategy" yaml:"strategy"`
	InitialDelay time.Duration   `mapstructure:"initial_delay" json:"initial_delay" yaml:"initial_delay"`
	MaxDelay     time.Duration   `mapstructure:"max_delay" json:"max_delay" yaml:"max_delay"`
	MaxRetries   int             `mapstructure:"max_retries" json:"max_retries" yaml:"max_retries"`
	Multiplier   float64         `mapstructure:"multiplier" json:"multiplier" yaml:"multiplier"` // Used for exponential backoff strategy
	Timeout      time.Duration   `mapstructure:"timeout" json:"timeout" yaml:"timeout"`
}

func (BackoffConfig) NextDelay

func (c BackoffConfig) NextDelay(prev time.Duration) time.Duration

func (BackoffConfig) Validate

func (c BackoffConfig) Validate() error

type BackoffStrategy

type BackoffStrategy string
const (
	BackoffFixed       BackoffStrategy = "fixed"
	BackoffExponential BackoffStrategy = "exponential"
)

type Result

type Result[T any] struct {
	Index int // original position in the input slice
	Item  T
	Err   error
}

Result holds the outcome for one item.

func RunBulk

func RunBulk[T any](ctx context.Context, items []T, parallel int, fn WorkFunc[T]) []Result[T]

RunBulk runs fn over items with up to 'parallel' workers. - If parallel <= 0, it defaults to min(8, len(items)). - Results preserve input order (results[i] corresponds to items[i]). - Honors context cancellation; any not-yet-dispatched items are marked with ctx.Err().

type WorkFunc

type WorkFunc[T any] func(ctx context.Context, item T) error

WorkFunc is the per-item function you want to run.

Jump to

Keyboard shortcuts

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