task

package
v0.0.63 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsyncExecute

func AsyncExecute[T any](ctx context.Context, fn func(ctx context.Context) (T, error)) <-chan AsyncResult[T]

AsyncExecute executes function asynchronously.

func BatchConcurrent

func BatchConcurrent[T, R any](ctx context.Context, concurrency int, slice []T, fn func(context.Context, T) (R, error)) ([]R, error)

BatchConcurrent batch execute function concurrently. The concurrency indicates how many fn are executing at the same time.

func ConExecute added in v0.0.62

func ConExecute(ctx context.Context, limit int, timeout time.Duration, tasks ...Task) error

ConExecute concurrently execute tasks with concurrent upper limit. If timeout is 0, there will be no timeout. If any one of tasks reports an error and the others are interrupted immediately.

func ConExecuteAll added in v0.0.62

func ConExecuteAll(ctx context.Context, limit int, tasks ...Task) (errs []error)

ConExecuteAll concurrently executes all tasks with concurrent upper limit. If one of tasks reports an error, continue to execute the remaining tasks and return all errors occurred.

func DoWithRetry

func DoWithRetry(ctx context.Context, f func() error, maxAttempts int, backoff time.Duration) error

func SeqExecute added in v0.0.62

func SeqExecute(ctx context.Context, tasks ...Task) error

SeqExecute executes tasks sequentially. If an error is encountered, return immediately.

func SeqExecuteAll added in v0.0.62

func SeqExecuteAll(ctx context.Context, tasks ...Task) (errs []error)

SeqExecuteAll executes all tasks sequentially. If one of tasks reports an error, continue to execute the remaining tasks and return all errors occurred.

Types

type AsyncResult

type AsyncResult[T any] struct {
	Val T
	Err error
}

AsyncResult is the result of the function executed asynchronously.

type Task

type Task func(ctx context.Context) error

Task is a function that takes a context and returns an error.

Jump to

Keyboard shortcuts

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