dataflow

package
v1.0.0-beta.3 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2022 License: Apache-2.0, BSD-2-Clause Imports: 0 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmptyNext

func EmptyNext[T any](param T) error

EmptyNext is an implementation of Next that does nothing.

Types

type Callback

type Callback[T any] func(param T)

Callback represents the interface for the callback functions.

type ChainedCommand

type ChainedCommand[T any] func(param T, next Next[T]) error

ChainedCommand represents the interface for the callbacks used in a DataFlow.

type DataFlow

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

DataFlow represents a chain of commands where the next command gets executed by the previous one passing on a common object holding the shared state. The recursive nature of the calls causes acquired resources (e.g. CachedObjects) to be held until the full data flow terminates.

This allows us to pass through unwrapped objects in most of the business logic which relaxes the stress on the caching layer and makes the code less verbose.

func New

func New[T any](commands ...ChainedCommand[T]) (dataFlow *DataFlow[T])

New creates a new DataFlow from the given ChainedCommands.

func (*DataFlow[T]) ChainedCommand

func (d *DataFlow[T]) ChainedCommand(param T, next Next[T]) error

ChainedCommand is a method that exposes the DataFlow as a ChainedCommand - use without calling it (without parentheses).

func (*DataFlow[T]) Run

func (d *DataFlow[T]) Run(param T) (err error)

Run executes the DataFlow with the given parameter. It aborts execution and returns an error if any of the chained commands returns an error.

Note: A DataFlow can only be run a single.

func (*DataFlow[T]) WithAbortCallback

func (d *DataFlow[T]) WithAbortCallback(callback Callback[T]) *DataFlow[T]

WithAbortCallback modifies the DataFlow to execute a callback after it has been aborted.

func (*DataFlow[T]) WithErrorCallback

func (d *DataFlow[T]) WithErrorCallback(callback ErrorCallback[T]) *DataFlow[T]

WithErrorCallback modifies the DataFlow to execute a callback after it has ended with an error.

func (*DataFlow[T]) WithSuccessCallback

func (d *DataFlow[T]) WithSuccessCallback(callback Callback[T]) *DataFlow[T]

WithSuccessCallback modifies the DataFlow to execute a callback after all its commands have been executed.

func (*DataFlow[T]) WithTerminationCallback

func (d *DataFlow[T]) WithTerminationCallback(callback Callback[T]) *DataFlow[T]

WithTerminationCallback modifies the DataFlow to execute a callback after it has terminated.

type ErrorCallback

type ErrorCallback[T any] func(err error, param T)

ErrorCallback represents the interface for the error callback functions.

type Next

type Next[T any] func(param T) error

Next represents the interface for next step in ChainedCommand.

Jump to

Keyboard shortcuts

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