Documentation
¶
Index ¶
- Constants
- Variables
- func ApplyChan[T any](input <-chan T, fn func(in T), opts ...ApplyOption)
- func ApplySlice[T any](input []T, fn func(in T), opts ...ApplyOption)
- func Execute(cbs ...func() error) []error
- func ExecuteOpts(cbs []func() error, opts ...ExecuteOption) []error
- func MapChan[Input any, Output any](input <-chan Input, fn func(in Input) (Output, error), opts ...MapOption) (<-chan Output, <-chan error)
- func MapSlice[Input any, Output any](input []Input, fn func(in Input) (Output, error), opts ...MapOption) ([]Output, []error)
- func MapSliceOrdered[Input any, Output any](input []Input, fn func(in Input) (Output, error), opts ...MapOption) ([]Output, []error)
- type ApplyOption
- type ConcurrencyLimiter
- type ExecuteOption
- type MapOption
Constants ¶
View Source
const (
ApplyDefaultConcurrency = 10
)
View Source
const (
ExecuteDefaultConcurrency = 10
)
View Source
const (
MapDefaultConcurrency = 10
)
Variables ¶
View Source
var ErrMapSkip = errors.New("skip")
ErrMapSkip is a special error that can be returned from Map function to skip the item.
Functions ¶
func ApplyChan ¶
func ApplyChan[T any](input <-chan T, fn func(in T), opts ...ApplyOption)
ApplyChan executes `fn` on each element of `input` channel in multiple threads. Options:
WithApplyConcurrency(int) - limits the number of parallel threads. Default: ApplyDefaultConcurrency
To stop processing, close `input` channel.
func ApplySlice ¶
func ApplySlice[T any](input []T, fn func(in T), opts ...ApplyOption)
ApplySlice does the same as ApplyChan, but works with slice instead of a channel.
func ExecuteOpts ¶
func ExecuteOpts(cbs []func() error, opts ...ExecuteOption) []error
ExecuteOpts executes slice of callback functions `cbs` with custom options.
func MapChan ¶
func MapChan[Input any, Output any](input <-chan Input, fn func(in Input) (Output, error), opts ...MapOption) (<-chan Output, <-chan error)
MapChan executes `fn` on each element of `input` channel in several threads.
Types ¶
type ApplyOption ¶
type ApplyOption interface {
// contains filtered or unexported methods
}
func WithApplyConcurrency ¶
func WithApplyConcurrency(concurrency int) ApplyOption
type ConcurrencyLimiter ¶
type ConcurrencyLimiter interface {
// Acquire acquires a slot in the concurrency limiter.
// Blocks until a slot is available.
Acquire()
// Release releases a slot in the concurrency limiter.
Release()
}
ConcurrencyLimiter is a helper that can limit amount of concurrently processed requests. See concurrency_limiter_test.go for usage example.
func NewConcurrencyLimiter ¶
func NewConcurrencyLimiter(concurrency int) ConcurrencyLimiter
type ExecuteOption ¶
type ExecuteOption interface {
// contains filtered or unexported methods
}
func WithExecuteConcurrency ¶
func WithExecuteConcurrency(concurrency int) ExecuteOption
type MapOption ¶
type MapOption interface {
// contains filtered or unexported methods
}
func WithMapConcurrency ¶
func WithMapStopOnFirstError ¶
func WithMapStopOnFirstError() MapOption
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
apply
command
|
|
|
concurrency_limiter
command
|
|
|
execute
command
|
|
|
map
command
|
Click to show internal directories.
Click to hide internal directories.