graph

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterCodec

func RegisterCodec[I, O any](nb *Builder, middleFunc node.MiddleFunc[I, O])

RegisterCodec registers a Codec into the graph builder. A Codec is a node.MiddleFunc function that allows converting data types and it's automatically inserted when a node with a given output type is connected to a node with a different input type. When nodes with different types are connected, a codec converting between both MUST have been registered previously. Otherwise the graph Build method will fail.

func RegisterMiddle

func RegisterMiddle[CFG stage.Instancer, I, O any](nb *Builder, b stage.MiddleProvider[CFG, I, O])

RegisterMiddle registers a stage.MiddleProvider into the graph builder. When the Build method is invoked later, any configuration field associated with the MiddleProvider will result in the instantiation of a node.Middle with the provider's returned function.

func RegisterStart

func RegisterStart[CFG stage.Instancer, O any](nb *Builder, b stage.StartProvider[CFG, O])

RegisterStart registers a stage.StartProvider into the graph builder. When the Build method is invoked later, any configuration field associated with the StartProvider will result in the instantiation of a node.Start with the provider's returned function.

func RegisterTerminal

func RegisterTerminal[CFG stage.Instancer, I any](nb *Builder, b stage.TerminalProvider[CFG, I])

RegisterTerminal registers a stage.TerminalProvider into the graph builder. When the Build method is invoked later, any configuration field associated with the TerminalProvider will result in the instantiation of a node.Terminal with the provider's returned function.

Types

type Builder

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

Builder helps to build a graph and to connect their nodes. It takes care of instantiating all its stages given a name and a type, as well as connect them. If two connected stages have incompatible types, it will insert a codec in between to translate between the stage types

func NewBuilder

func NewBuilder(options ...node.Option) *Builder

NewBuilder instantiates a Graph Builder with the default configuration, which can be overridden via the arguments.

func (*Builder) Build

func (b *Builder) Build(cfg ConnectedConfig) (Graph, error)

Build creates a Graph where each node corresponds to a field in the passed Configuration struct. The nodes will be connected according to the ConnectedConfig "source" --> ["destination"...] map.

type ConnectedConfig

type ConnectedConfig interface {
	// Connections returns a map representing the connection of the node graphs, where
	// the key contains the instance ID of the source node, and the value contains an
	// array of the destination nodes' instance IDs.
	Connections() map[string][]string
}

ConnectedConfig describes the interface that any struct passed to the builder.Build method must fullfill. Consider embedding the Connector type into your struct for automatic implementation of the interface.

type Connector

type Connector map[string][]string

Connector is a convenience implementor of the ConnectedConfig interface, required to build any graph. It can be embedded into any configuration struct that is passed as argument into the builder.Build method.

Key: instance ID of the source node. Value: array of destination node instance IDs.

func (Connector) Connections

func (c Connector) Connections() map[string][]string

Connections returns the connection map represented by the Connector

type Graph

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

Graph is set of Start Nodes that generate information that is forwarded to Middle or Terminal nodes, which process that information. It must be created from the Builder type.

func (*Graph) Run

func (g *Graph) Run()

Run all the stages of the graph and wait until all the nodes stopped processing.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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