parallelisation

package module
v1.172.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 16 Imported by: 3 modules, 5 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

  • Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors. All rights reserved.

  • SPDX-License-Identifier: Apache-2.0

  • Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors. All rights reserved.

  • SPDX-License-Identifier: Apache-2.0

  • Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors. All rights reserved.

  • SPDX-License-Identifier: Apache-2.0

  • Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors. All rights reserved.

  • SPDX-License-Identifier: Apache-2.0

Package parallelisation defines a module for `Concurrency`

  • Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors. All rights reserved.

  • SPDX-License-Identifier: Apache-2.0

  • Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors. All rights reserved.

  • SPDX-License-Identifier: Apache-2.0

  • Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors. All rights reserved.

  • SPDX-License-Identifier: Apache-2.0

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BreakOnError

func BreakOnError(ctx context.Context, executionOptions *StoreOptions, contextualFunc ...ContextualFunc) error

BreakOnError executes each functions in the group until an error is found or the context gets cancelled.

func BreakOnErrorOrEOF

func BreakOnErrorOrEOF(ctx context.Context, executionOptions *StoreOptions, contextualFunc ...ContextualFunc) error

BreakOnErrorOrEOF is similar to BreakOnError but also stops on EOF. However, in this case, no error is returned

func CloseAll

func CloseAll(cs ...io.Closer) error

CloseAll calls concurrently Close on all io.Closer implementations passed as arguments and returns the first error encountered

func CloseAllAndCollateErrors

func CloseAllAndCollateErrors(cs ...io.Closer) error

CloseAllAndCollateErrors calls concurrently Close on all io.Closer implementations passed as arguments and returns the errors encountered

func CloseAllFunc

func CloseAllFunc(cs ...CloseFunc) error

CloseAllFunc calls concurrently all Close functions passed as arguments and returns the first error encountered

func CloseAllFuncAndCollateErrors

func CloseAllFuncAndCollateErrors(cs ...CloseFunc) error

CloseAllFuncAndCollateErrors calls concurrently all Close functions passed as arguments and returns the errors encountered

func CloseAllWithContext

func CloseAllWithContext(ctx context.Context, cs ...io.Closer) error

CloseAllWithContext is similar to CloseAll but can be controlled using a context.

func CloseAllWithContextAndCollateErrors

func CloseAllWithContextAndCollateErrors(ctx context.Context, cs ...io.Closer) error

CloseAllWithContextAndCollateErrors is similar to CloseAllAndCollateErrors but can be controlled using a context.

func DetermineContextError

func DetermineContextError(ctx context.Context) error

DetermineContextError determines what the context error is if any.

func Filter

func Filter[T any](ctx context.Context, numWorkers int, s []T, f collection.FilterFunc[T]) (result []T, err error)

Filter is similar to collection.Filter but uses parallelisation.

func ForEach

func ForEach(ctx context.Context, executionOptions *StoreOptions, contextualFunc ...ContextualFunc) error

ForEach executes all the contextual functions according to the store options and returns an error if one occurred.

func Map

func Map[T1 any, T2 any](ctx context.Context, numWorkers int, s []T1, f collection.MapFunc[T1, T2]) (result []T2, err error)

Map is similar to collection.Map but uses parallelisation.

func MapConcurrent

func MapConcurrent[I any, O any](ctx context.Context, items []I, fn collection.MapFunc[I, O], options ...StoreOption) ([]O, error)

MapConcurrent is similar to collection.Map but uses store options instead of a dedicated worker-count parameter.

Results are returned in input order. Use Workers to limit parallelism.

func MapConcurrentRef

func MapConcurrentRef[I any, O any](ctx context.Context, items []I, fn collection.MapRefFunc[I, O], options ...StoreOption) ([]O, error)

MapConcurrentRef is similar to collection.MapRef but uses store options instead of a dedicated worker-count parameter.

Results are returned in input order. Nil mapped values are skipped.

func MapConcurrentSequence

func MapConcurrentSequence[I any, O any](ctx context.Context, items iter.Seq[I], fn collection.MapFunc[I, O], options ...StoreOption) ([]O, error)

MapConcurrentSequence is similar to collection.MapSequence but evaluates the mapping work concurrently and returns the eagerly collected result slice.

Results are returned in input order. Use Workers to limit parallelism.

func OrderedMap

func OrderedMap[T1 any, T2 any](ctx context.Context, numWorkers int, s []T1, f collection.MapFunc[T1, T2]) (result []T2, err error)

OrderedMap is similar to Map but ensures the results are in the same order as the input.

func Parallelise

func Parallelise(argList any, action func(arg any) (any, error), resultType reflect.Type) (results any, err error)

Parallelise parallelises an action over as many goroutines as specified by the argList and retrieves all the results when all the goroutines are done. To control the number of goroutines spawned, prefer WorkerPool

func Reject

func Reject[T any](ctx context.Context, numWorkers int, s []T, f collection.FilterFunc[T]) ([]T, error)

Reject is the opposite of Filter and returns the elements of collection for which the filtering function f returns false.

func RunActionWithParallelCheck

func RunActionWithParallelCheck(ctx context.Context, action ActionFunc, checkAction CheckFunc, checkPeriod time.Duration) (err error)

RunActionWithParallelCheck runs an action with a check in parallel The function performing the check should return true if the check was favourable; false otherwise. If the check did not have the expected result then the whole function would be cancelled.

func RunActionWithParallelCheckAndResult

func RunActionWithParallelCheckAndResult[T any](ctx context.Context, action ActionFunc, checkAction CheckWithResultFunc[T], onCheckResult ResultCheckFunc[T], checkPeriod time.Duration) (res T, ok bool, err error)

RunActionWithParallelCheck runs an action with a check in parallel The function performing the check should return true if the check should be repeated; false otherwise it should not. For more context about how the check ended, a result can be returned. If the check did not have the expected result then the whole function would be cancelled.

func RunActionWithTimeout

func RunActionWithTimeout(blockingAction func(stop chan bool) error, timeout time.Duration) (err error)

RunActionWithTimeout runs an action with timeout

func RunActionWithTimeoutAndCancelStore

func RunActionWithTimeoutAndCancelStore(ctx context.Context, timeout time.Duration, store *CancelFunctionStore, blockingAction func(context.Context) error) error

RunActionWithTimeoutAndCancelStore runs an action with timeout The cancel ExecutionGroup is used just to register the cancel function so that it can be called on Cancel.

func RunActionWithTimeoutAndContext

func RunActionWithTimeoutAndContext(ctx context.Context, timeout time.Duration, blockingAction func(context.Context) error) error

RunActionWithTimeoutAndContext runs an action with timeout blockingAction's context will be cancelled on exit.

func SafeSchedule

func SafeSchedule(ctx context.Context, period time.Duration, offset time.Duration, f func(context.Context, time.Time))

SafeSchedule calls function `f` regularly with a `period` and an `offset`, similarly to Schedule but with context control.

func SafeScheduleAfter

func SafeScheduleAfter(ctx context.Context, offset time.Duration, f func(context.Context, time.Time))

SafeScheduleAfter calls once function `f` after `offset` similarly to ScheduleAfter but stops the function is controlled by the context

func Schedule

func Schedule(ctx context.Context, period time.Duration, offset time.Duration, f func(time.Time))

Schedule calls function `f` regularly with a `period` and an `offset`.

func ScheduleAfter

func ScheduleAfter(ctx context.Context, offset time.Duration, f func(time.Time))

ScheduleAfter calls once function `f` after `offset`

func SchedulePeriodicCheckWithAction

func SchedulePeriodicCheckWithAction(ctx context.Context, checkFunc CheckFuncWithErr, actionFunc ActionFunc, pauseBetweenEvaluations time.Duration) error

SchedulePeriodicCheckWithAction continuously evaluates checkFunc and, when it returns true, executes actionFunc before waiting for pauseBetweenEvaluations. The loop stops when the context is cancelled or when either the checkFunc or the actionFunc returns an error.

func SleepWithContext

func SleepWithContext(ctx context.Context, delay time.Duration)

SleepWithContext performs an interruptable sleep Similar to time.Sleep() but also responding to context cancellation instead of blocking for the whole length of time.

func SleepWithInterruption

func SleepWithInterruption(stop chan bool, delay time.Duration)

SleepWithInterruption performs an interruptable sleep Similar to time.Sleep() but also interrupting when requested instead of blocking for the whole length of time.

func Transform

func Transform[I any, O any](ctx context.Context, inputs iter.Seq[I], transform TransformFunc[I, O], options ...StoreOption) ([]O, error)

Transform transforms inputs into outputs using the transform function.

func TransformInOrder

func TransformInOrder[I any, O any](ctx context.Context, inputs iter.Seq[I], transform TransformFunc[I, O], options ...StoreOption) ([]O, error)

TransformInOrder transforms inputs into outputs using the transform function but returns the output in the same order as the input.

func WaitUntil

func WaitUntil(ctx context.Context, evalCondition func(ctx2 context.Context) (bool, error), pauseBetweenEvaluations time.Duration) error

WaitUntil waits for a condition evaluated by evalCondition to be verified

func WaitWithContext

func WaitWithContext(ctx context.Context, wg IWaiter) (err error)

func WaitWithContextAndError

func WaitWithContextAndError(ctx context.Context, wg IErrorWaiter) (err error)

func WorkerPool

func WorkerPool[InputType, ResultType any](ctx context.Context, numWorkers int, jobs []InputType, f TransformFunc[InputType, ResultType]) (results []ResultType, err error)

WorkerPool parallelises an action using a worker pool of the size provided by numWorkers and retrieves all the results when all the actions have completed. It is similar to Parallelise but it uses generics instead of reflection and allows you to control the pool size

func WrapCloseToCancelFunc

func WrapCloseToCancelFunc(f CloseFunc) context.CancelFunc

func WrapContextualToCancelFunc

func WrapContextualToCancelFunc(f ContextualFunc) context.CancelFunc

Types

type ActionFunc

type ActionFunc func(ctx context.Context) (err error)

type CancelFunctionStore

type CancelFunctionStore struct {
	ExecutionGroup[context.CancelFunc]
}

func NewCancelFunctionsStore

func NewCancelFunctionsStore(options ...StoreOption) *CancelFunctionStore

NewCancelFunctionsStore creates a store for cancel functions. Whatever the options passed, all cancel functions will be executed and cleared. In other words, options `RetainAfterExecution` and `StopOnFirstError` would be discarded if selected to create the Cancel store

func (*CancelFunctionStore) Cancel

func (s *CancelFunctionStore) Cancel()

Cancel will execute the cancel functions in the store. Any errors will be ignored and Execute() is recommended if you need to know if a cancellation failed

func (*CancelFunctionStore) Clone

func (*CancelFunctionStore) Len

func (s *CancelFunctionStore) Len() int

func (*CancelFunctionStore) RegisterCancelFunction

func (s *CancelFunctionStore) RegisterCancelFunction(cancel ...context.CancelFunc)

func (*CancelFunctionStore) RegisterCancelStore

func (s *CancelFunctionStore) RegisterCancelStore(store *CancelFunctionStore)

type CheckFunc

type CheckFunc func(ctx context.Context) (ok bool)

type CheckFuncWithErr

type CheckFuncWithErr func(ctx context.Context) (ok bool, err error)

type CheckWithResultFunc

type CheckWithResultFunc[T any] func(ctx context.Context) (res T, ok bool)

type CloseFunc

type CloseFunc func() error

func WrapCancelToCloseFunc

func WrapCancelToCloseFunc(f context.CancelFunc) CloseFunc

func WrapCloserIntoCloseFunc

func WrapCloserIntoCloseFunc(closer io.Closer) CloseFunc

func WrapContextualToCloseFunc

func WrapContextualToCloseFunc(f ContextualFunc) CloseFunc

func (CloseFunc) Close

func (c CloseFunc) Close() error

type CloseFunctionStore

type CloseFunctionStore struct {
	ExecutionGroup[CloseFunc]
}

func NewCloseFunctionStore

func NewCloseFunctionStore(options ...StoreOption) *CloseFunctionStore

NewCloseFunctionStore returns a store closing functions which will all be called on Close(). The first error received if any will be returned.

func NewCloseFunctionStoreStore

func NewCloseFunctionStoreStore(stopOnFirstError bool) *CloseFunctionStore

NewCloseFunctionStoreStore is exactly the same as NewConcurrentCloseFunctionStore but without a typo in the name.

func NewCloseOnceGroup

func NewCloseOnceGroup(options ...StoreOption) *CloseFunctionStore

NewCloseOnceGroup is the same as NewCloseFunctionStore but ensures any closing functions are only executed once.

func NewConcurrentCloseFunctionStore

func NewConcurrentCloseFunctionStore(stopOnFirstError bool) *CloseFunctionStore

NewConcurrentCloseFunctionStore returns a store closing functions which will all be called concurrently on Close(). The first error received will be returned. Prefer using NewCloseFunctionStore where possible

func NewConcurrentCloseOnceFunctionStore

func NewConcurrentCloseOnceFunctionStore(stopOnFirstError bool) *CloseFunctionStore

NewConcurrentCloseOnceFunctionStore returns a store closing functions once on Close(). It is similar to NewConcurrentCloseFunctionStore otherwise.

func (*CloseFunctionStore) Clone

func (*CloseFunctionStore) Close

func (s *CloseFunctionStore) Close() error

func (*CloseFunctionStore) Len

func (s *CloseFunctionStore) Len() int

func (*CloseFunctionStore) RegisterCancelFunction

func (s *CloseFunctionStore) RegisterCancelFunction(cancelFunc ...context.CancelFunc)

func (*CloseFunctionStore) RegisterCancelStore

func (s *CloseFunctionStore) RegisterCancelStore(cancelStore *CancelFunctionStore)

func (*CloseFunctionStore) RegisterCloseFunction

func (s *CloseFunctionStore) RegisterCloseFunction(closerObj ...CloseFunc)

type CloserStore

type CloserStore struct {
	ExecutionGroup[io.Closer]
}

func NewCloserOnceStore

func NewCloserOnceStore(stopOnFirstError bool) *CloserStore

NewCloserOnceStore is similar to NewCloserStore but only close the closers once.

func NewCloserStore

func NewCloserStore(stopOnFirstError bool) *CloserStore

NewCloserStore returns a store of io.Closer object which will all be closed concurrently on Close(). The first error received will be returned

func NewCloserStoreWithOptions

func NewCloserStoreWithOptions(opts ...StoreOption) *CloserStore

NewCloserStoreWithOptions returns a store of io.Closer object which will all be closed on Close(). The first error received if any will be returned

func (*CloserStore) Clone

func (s *CloserStore) Clone() IExecutionGroup[io.Closer]

func (*CloserStore) Close

func (s *CloserStore) Close() error

func (*CloserStore) Len

func (s *CloserStore) Len() int

func (*CloserStore) RegisterCloser

func (s *CloserStore) RegisterCloser(closerObj ...io.Closer)

type CompoundExecutionGroup

type CompoundExecutionGroup struct {
	ContextualFunctionGroup
}

func NewCompoundExecutionGroup

func NewCompoundExecutionGroup(options ...StoreOption) *CompoundExecutionGroup

NewCompoundExecutionGroup returns an execution group made of executors

func (*CompoundExecutionGroup) Clone

func (*CompoundExecutionGroup) RegisterExecutor

func (g *CompoundExecutionGroup) RegisterExecutor(group ...IExecutor)

RegisterExecutor registers executors

type ContextualFunc

type ContextualFunc func(ctx context.Context) error

func WrapCancelToContextualFunc

func WrapCancelToContextualFunc(f context.CancelFunc) ContextualFunc

func WrapCloseToContextualFunc

func WrapCloseToContextualFunc(f CloseFunc) ContextualFunc

type ContextualFunctionGroup

type ContextualFunctionGroup struct {
	ExecutionGroup[ContextualFunc]
}

func NewContextualGroup

func NewContextualGroup(options ...StoreOption) *ContextualFunctionGroup

NewContextualGroup returns a group executing contextual functions.

func (*ContextualFunctionGroup) Clone

type ExecuteFunc

type ExecuteFunc[T any] func(ctx context.Context, element T) error

type ExecutionGroup

type ExecutionGroup[T any] struct {
	// contains filtered or unexported fields
}

func NewExecutionGroup

func NewExecutionGroup[T any](executeFunc ExecuteFunc[T], options ...StoreOption) *ExecutionGroup[T]

NewExecutionGroup returns an execution group which executes functions according to store options.

func NewOrderedExecutionGroup

func NewOrderedExecutionGroup[T any](executeFunc OrderedExecuteFunc[T], options ...StoreOption) *ExecutionGroup[T]

NewOrderedExecutionGroup returns an execution group which executes functions according to store options. It also keeps track of the input index.

func (*ExecutionGroup[T]) Clone

func (s *ExecutionGroup[T]) Clone() IExecutionGroup[T]

func (*ExecutionGroup[T]) CopyFunctions

func (s *ExecutionGroup[T]) CopyFunctions(g IExecutionGroup[T])

func (*ExecutionGroup[T]) Execute

func (s *ExecutionGroup[T]) Execute(ctx context.Context) (err error)

Execute executes all the function in the group according to store options.

func (*ExecutionGroup[T]) Len

func (s *ExecutionGroup[T]) Len() int

func (*ExecutionGroup[T]) RegisterFunction

func (s *ExecutionGroup[T]) RegisterFunction(function ...T)

RegisterFunction registers functions to the group.

func (*ExecutionGroup[T]) RegisterFunctions

func (s *ExecutionGroup[T]) RegisterFunctions(function iter.Seq[T])

RegisterFunctions registers a sequence of functions to the group.

type ICompoundExecutionGroup

type ICompoundExecutionGroup[T any] interface {
	IExecutionGroup[T]
	// RegisterExecutor registers executors of any kind to the group: they could be functions or subgroups.
	RegisterExecutor(executor ...IExecutor)
}

type IErrorWaiter

type IErrorWaiter interface {
	Wait() error
}

IErrorWaiter can be used to wait on errgroups and similar types where Wait() returns an error This is used to support use in the WaitWithContextAndError function to wait but listen to contexts

type IExecutionGroup

type IExecutionGroup[T any] interface {
	IExecutor
	RegisterFunction(function ...T)
	// RegisterFunctions registers a sequence of functions to the group.
	RegisterFunctions(function iter.Seq[T])
	// CopyFunctions copies the registered functions to group g
	CopyFunctions(g IExecutionGroup[T])
	Len() int
	// Clone returns a new execution group containing the same registered functions
	// as the original. The cloned group does not inherit any execution state, so
	// none of the functions are considered executed. Calling Execute on the clone
	// will run all registered functions again, regardless of whether they were
	// previously executed in the original group.
	Clone() IExecutionGroup[T]
}

type IExecutor

type IExecutor interface {
	// Execute executes all the functions in the group.
	Execute(ctx context.Context) error
}

type IWaiter

type IWaiter interface {
	Wait()
}

IWaiter can be used to wait on sync WaitGroups and similar types where Wait() does not return an error This is used to support use in the WaitWithContext function to wait but listen to contexts

type OrderedExecuteFunc

type OrderedExecuteFunc[T any] func(ctx context.Context, index int, element T) error

type PriorityExecutionGroup

type PriorityExecutionGroup[T any] struct {
	// contains filtered or unexported fields
}

func NewPriorityContextualGroup

func NewPriorityContextualGroup(options ...StoreOption) *PriorityExecutionGroup[ContextualFunc]

NewContextualGroupWithPriority returns a group executing contextual functions that will be run in priority order.

func NewPriorityExecutionGroup

func NewPriorityExecutionGroup(options ...StoreOption) *PriorityExecutionGroup[IExecutor]

NewPriorityExecutionGroup returns an execution group that can execute functions in order according to priority rules. Parallel commands with differing priorities will be executed in groups according to their priority. Sequential commands will be executed in order of their priority, no guarantees are made about the order of when the priority is the same as another command.

func (*PriorityExecutionGroup[T]) Clone

func (g *PriorityExecutionGroup[T]) Clone() IExecutionGroup[T]

func (*PriorityExecutionGroup[T]) CopyAllPriorityFunctions

func (g *PriorityExecutionGroup[T]) CopyAllPriorityFunctions(d *PriorityExecutionGroup[T])

func (*PriorityExecutionGroup[T]) CopyFunctions

func (g *PriorityExecutionGroup[T]) CopyFunctions(d IExecutionGroup[T])

func (*PriorityExecutionGroup[T]) CopyPriorityFunctions

func (g *PriorityExecutionGroup[T]) CopyPriorityFunctions(priority uint, d IExecutionGroup[T])

func (*PriorityExecutionGroup[T]) Execute

func (g *PriorityExecutionGroup[T]) Execute(ctx context.Context) error

Execute will execute all the groups according to the priorities of the functions

func (*PriorityExecutionGroup[T]) GetPriorityGroup

func (g *PriorityExecutionGroup[T]) GetPriorityGroup(priority uint) IExecutionGroup[T]

func (*PriorityExecutionGroup[T]) Len

func (g *PriorityExecutionGroup[T]) Len() (n int)

func (*PriorityExecutionGroup[T]) RegisterFunction

func (g *PriorityExecutionGroup[T]) RegisterFunction(function ...T)

RegisterExecutor registers executors with a priority of zero (highest priority)

func (*PriorityExecutionGroup[T]) RegisterFunctionWithPriority

func (g *PriorityExecutionGroup[T]) RegisterFunctionWithPriority(priority uint, function ...T)

RegisterExecutor registers executors with a specific priority (lower values indidcate higher priority)

func (*PriorityExecutionGroup[T]) RegisterFunctions

func (g *PriorityExecutionGroup[T]) RegisterFunctions(functionSeq iter.Seq[T])

func (*PriorityExecutionGroup[T]) RegisterFunctionsWithPriority

func (g *PriorityExecutionGroup[T]) RegisterFunctionsWithPriority(priority uint, functionSeq iter.Seq[T])

type ResultCheckFunc

type ResultCheckFunc[T any] func(res T) (err error)

type StoreOption

type StoreOption func(*StoreOptions) *StoreOptions
var AnyTimes StoreOption = func(o *StoreOptions) *StoreOptions {
	if o == nil {
		o = DefaultOptions()
	}
	o.onlyOnce = false
	return o
}

AnyTimes will allow the functions to be executed as often that they might be.

var ClearAfterExecution StoreOption = func(o *StoreOptions) *StoreOptions {
	if o == nil {
		o = DefaultOptions()
	}
	o.clearOnExecution = true
	return o
}

ClearAfterExecution clears the ExecutionGroup after execution.

var ExecuteAll StoreOption = func(o *StoreOptions) *StoreOptions {
	if o == nil {
		o = DefaultOptions()
	}
	o.stopOnFirstError = false
	return o
}

ExecuteAll executes all functions in the ExecutionGroup even if an error is raised. the first error raised is then returned.

var JoinErrors StoreOption = func(o *StoreOptions) *StoreOptions {
	if o == nil {
		o = DefaultOptions()
	}
	o.stopOnFirstError = false
	o.joinErrors = true
	return o
}

JoinErrors will collate any errors which happened when executing functions in ExecutionGroup. This option should not be used in combination to StopOnFirstError.

var OnlyOnce StoreOption = func(o *StoreOptions) *StoreOptions {
	if o == nil {
		o = DefaultOptions()
	}
	o.onlyOnce = true
	return o
}

OnlyOnce will ensure the function are executed only once if they do.

var Parallel StoreOption = func(o *StoreOptions) *StoreOptions {
	if o == nil {
		o = DefaultOptions()
	}
	o.sequential = false
	return o
}

Parallel ensures every function registered in the ExecutionGroup is executed concurrently in the order they were registered.

var RetainAfterExecution StoreOption = func(o *StoreOptions) *StoreOptions {
	if o == nil {
		o = DefaultOptions()
	}
	o.clearOnExecution = false
	return o
}

RetainAfterExecution keep the ExecutionGroup intact after execution (no reset).

var Sequential StoreOption = func(o *StoreOptions) *StoreOptions {
	if o == nil {
		o = DefaultOptions()
	}
	o.sequential = true
	return o
}

Sequential ensures every function registered in the ExecutionGroup is executed sequentially in the order they were registered.

var SequentialInReverse StoreOption = func(o *StoreOptions) *StoreOptions {
	if o == nil {
		o = DefaultOptions()
	}
	o.sequential = true
	o.reverse = true
	return o
}

SequentialInReverse ensures every function registered in the ExecutionGroup is executed sequentially but in the reverse order they were registered.

var StopOnFirstError StoreOption = func(o *StoreOptions) *StoreOptions {
	if o == nil {
		o = DefaultOptions()
	}
	o.stopOnFirstError = true
	o.joinErrors = false
	return o
}

StopOnFirstError stops ExecutionGroup execution on first error.

func Workers

func Workers(workers int) StoreOption

Workers defines a limit number of workers for executing the function registered in the ExecutionGroup.

type StoreOptions

type StoreOptions struct {
	// contains filtered or unexported fields
}

func DefaultOptions

func DefaultOptions() *StoreOptions

DefaultOptions returns the default store configuration

func WithOptions

func WithOptions(option ...StoreOption) (opts *StoreOptions)

WithOptions defines a store configuration.

func (*StoreOptions) Apply

func (o *StoreOptions) Apply(opt StoreOption) *StoreOptions

func (*StoreOptions) Default

func (o *StoreOptions) Default() *StoreOptions

func (*StoreOptions) Merge

func (o *StoreOptions) Merge(opts *StoreOptions) *StoreOptions

func (*StoreOptions) MergeWithOptions

func (o *StoreOptions) MergeWithOptions(opt ...StoreOption) *StoreOptions

func (*StoreOptions) Options

func (o *StoreOptions) Options() []StoreOption

func (*StoreOptions) Overwrite

func (o *StoreOptions) Overwrite(opts *StoreOptions) *StoreOptions

func (*StoreOptions) WithOptions

func (o *StoreOptions) WithOptions(opts ...StoreOption) *StoreOptions

type TransformFunc

type TransformFunc[I any, O any] func(context.Context, I) (output O, success bool, err error)

TransformFunc defines a transformation function which converts an input into an output.

type TransformGroup

type TransformGroup[I any, O any] struct {
	ExecutionGroup[I]
	// contains filtered or unexported fields
}

func NewTransformGroup

func NewTransformGroup[I any, O any](transform TransformFunc[I, O], options ...StoreOption) *TransformGroup[I, O]

NewTransformGroup returns a group transforming inputs into outputs. To register inputs, call the Input function To perform the transformation of inputs, then call Transform To retrieve the output, then call Output

func (*TransformGroup[I, O]) Clone

func (g *TransformGroup[I, O]) Clone() IExecutionGroup[I]

func (*TransformGroup[I, O]) InputSequence

func (g *TransformGroup[I, O]) InputSequence(ctx context.Context, i iter.Seq[I]) error

InputSequence registers inputs to transform.

func (*TransformGroup[I, O]) Inputs

func (g *TransformGroup[I, O]) Inputs(ctx context.Context, i ...I) error

Inputs registers inputs to transform.

func (*TransformGroup[I, O]) OrderedOutputs

func (g *TransformGroup[I, O]) OrderedOutputs(ctx context.Context) ([]O, error)

OrderedOutputs returns any input which have been transformed when the Transform function was called. The returned output is in the same order as the input slice.

func (*TransformGroup[I, O]) Outputs

func (g *TransformGroup[I, O]) Outputs(ctx context.Context) ([]O, error)

Outputs returns any input which have been transformed when the Transform function was called.

func (*TransformGroup[I, O]) Transform

func (g *TransformGroup[I, O]) Transform(ctx context.Context) error

Transform actually performs the transformation over all registered inputs.

Directories

Path Synopsis
mocks module

Jump to

Keyboard shortcuts

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