conc

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2023 License: MIT Imports: 5 Imported by: 0

README

conc

A concurrency control library in Golang

Donation

View https://guoyk.xyz

Credits

Guo Y.K., MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Errs

type Errs []error

Errs slice of error, may contain nils, user can known which task failed, which not failed

func (Errs) Error

func (errs Errs) Error() string

func (Errs) Sanitize

func (errs Errs) Sanitize() error

Sanitize, if all elements in Errs is nil, return nil, else return Errs

type Limiter

type Limiter interface {
	Take()
	Done()
}

func NewFixedLimiter

func NewFixedLimiter(limit int) Limiter

type Task

type Task interface {
	Do(ctx context.Context) error
}

func Error added in v1.2.0

func Error(err error) Task

Error create Task always returns error

func NoError added in v1.2.0

func NoError(task Task) Task

NoError wrap a Task and never returns error

func Parallel

func Parallel(tasks ...Task) Task

Parallel, create a Task run all tasks in parallel, one failed, others will be cancelled via context returns Errs indicating which task failed, which not failed

func ParallelFailSafe

func ParallelFailSafe(tasks ...Task) Task

ParallelFailSafe, create a Task run all tasks in parallel, one failed, others will still Run returns Errs indicating which task failed, which not failed

func ParallelFailSafeWithLimit

func ParallelFailSafeWithLimit(limit int, tasks ...Task) Task

ParallelFailSafeWithLimit, create a Task run all tasks in parallel with limit using token based concurrency control returns Errs indicating which task failed, which not failed

func ParallelWithLimit

func ParallelWithLimit(limit int, tasks ...Task) Task

ParallelWithLimit, create a Task run all tasks in parallel with limit, one failed, others will be cancelled via context returns Errs indicating which task failed, which not failed

func Periodic added in v1.2.0

func Periodic(task Task, dur time.Duration, init bool) Task

Periodic returns a Task do input Task periodically

func Serial

func Serial(tasks ...Task) Task

Serial run tasks in serial, return on first failed

func SerialFailSafe

func SerialFailSafe(tasks ...Task) Task

SerialFailSafe run tasks in serial, one failed will not interfere others

type TaskFunc

type TaskFunc func(ctx context.Context) error

func (TaskFunc) Do added in v1.1.0

func (t TaskFunc) Do(ctx context.Context) error

Jump to

Keyboard shortcuts

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