flow

package
v0.0.0-...-4fef700 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrHandlerMissingAction        = errors.New("no action function specified for handler")
	ErrParallelHandlerNotSupported = errors.New("parallel handler is supported only in EffectFlow")
)

Functions

func ExecuteEffectFlow

func ExecuteEffectFlow(f *EffectFlow[any]) error

func ExecutePureFlow

func ExecutePureFlow(f *PureFlow[any]) error

Types

type EffectFlow

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

func NewEffectFlow

func NewEffectFlow(flowOpts *Opts, terminalOnError func(err error), handlers ...*Handler[any]) (*EffectFlow[any], error)

NewEffectFlow creates effect flow. If terminalOnError is specified this function will be used as global error callback and no handler onError functions will be called. to override this behavior look at Opts.ExecuteOnErrorAlways

func (EffectFlow) Start

func (r EffectFlow) Start() error

type Handler

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

func NewHandler

func NewHandler[T any](action HandlerAction[T], onError HandlerErrorAction[T]) *Handler[T]

func NewParallelHandlerGroup

func NewParallelHandlerGroup[T any](onError HandlerErrorAction[T], handlers ...*Handler[T]) *Handler[T]

NewParallelHandlerGroup creates handler wrapping multiple handlers marked for parallel execution. if any error occurs in parallel handler, onError of all handlers in ParallelGroup are called, if error occurs in handler ordinary handler that was called after ParallelGroup, only ParallelGroup onError will be executed

type HandlerAction

type HandlerAction[T any] func(T) (T, error)

type HandlerErrorAction

type HandlerErrorAction[T any] func(*Handler[T], error)

type Opts

type Opts struct {
	// Name optional name for flow. If not specified, random name will be generated
	Name string
	// if ExecuteOnErrorAlways is true, every OnError function will be called in every handler event if terminalOnError is specified
	ExecuteOnErrorAlways bool
}

type PureFlow

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

func NewPureFlow

func NewPureFlow[T any](flowOpts *Opts, terminalOnError func(err error), initialData T, handlers ...*Handler[T]) (*PureFlow[T], error)

NewPureFlow creates effect flow. If terminalOnError is specified this function will be used as global error callback and no handler onError functions will be called. to override this behavior look at Opts.ExecuteOnErrorAlways

func (PureFlow) Start

func (r PureFlow) Start() error

Jump to

Keyboard shortcuts

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