node

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: 2 Imported by: 0

Documentation

Overview

Package node provides functionalities to create nodes and interconnect them. A Node is a function container that can be connected via channels to other nodes. A node can send data to multiple nodes, and receive data from multiple nodes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Middle

type Middle[IN, OUT any] struct {
	// contains filtered or unexported fields
}

Middle is any intermediate node that receives data from another node, processes/filters it, and forwards the data to another node. An Middle node must have at least one output node.

func AsMiddle

func AsMiddle[IN, OUT any](fun MiddleFunc[IN, OUT], opts ...Option) *Middle[IN, OUT]

AsMiddle wraps an MiddleFunc into an Middle node.

func (*Middle[IN, OUT]) InType

func (m *Middle[IN, OUT]) InType() reflect.Type

func (*Middle[IN, OUT]) OutType

func (m *Middle[IN, OUT]) OutType() reflect.Type

func (*Middle[IN, OUT]) SendsTo

func (s *Middle[IN, OUT]) SendsTo(outputs ...Receiver[OUT])

type MiddleFunc

type MiddleFunc[IN, OUT any] func(in <-chan IN, out chan<- OUT)

MiddleFunc is a function that receives a readable channel as first argument, and a writable channel as second argument. It must process the inputs from the input channel until it's closed.

type Option added in v0.3.0

type Option func(options *creationOptions)

Option allows overriding the default values of node instantiation

func ChannelBufferLen added in v0.3.0

func ChannelBufferLen(length int) Option

ChannelBufferLen is a node.Option that allows specifying the length of the input channels for a given node. The default value is 0, which means that the channels are unbuffered.

type Receiver

type Receiver[IN any] interface {

	// InType returns the inner type of the Receiver's input channel
	InType() reflect.Type
	// contains filtered or unexported methods
}

Receiver is any node that can receive data from another node: node.Middle and node.Terminal

type Sender

type Sender[OUT any] interface {
	// SendsTo connect a sender with a group of receivers
	SendsTo(...Receiver[OUT])
	// OutType returns the inner type of the Sender's output channel
	OutType() reflect.Type
}

Sender is any node that can send data to another node: node.Start and node.Middle

type Start added in v0.4.0

type Start[OUT any] struct {
	// contains filtered or unexported fields
}

Start nodes are the starting points of a graph. This is, all the nodes that bring information from outside the graph: e.g. because they generate them or because they acquire them from an external source like a Web Service. A graph must have at least one Start node. An Start node must have at least one output node.

func AsStart added in v0.4.0

func AsStart[OUT any](fun StartFunc[OUT]) *Start[OUT]

AsStart wraps an StartFunc into an Start node.

func (*Start[OUT]) OutType added in v0.4.0

func (s *Start[OUT]) OutType() reflect.Type

OutType is deprecated. It will be removed in future versions.

func (*Start[OUT]) SendsTo added in v0.4.0

func (s *Start[OUT]) SendsTo(outputs ...Receiver[OUT])

func (*Start[OUT]) Start added in v0.4.0

func (i *Start[OUT]) Start()

type StartFunc added in v0.4.0

type StartFunc[OUT any] func(out chan<- OUT)

StartFunc is a function that receives a writable channel as unique argument, and sends value to that channel during an indefinite amount of time.

type Terminal

type Terminal[IN any] struct {
	// contains filtered or unexported fields
}

Terminal is any node that receives data from another node and does not forward it to another node, but can process it and send the results to outside the graph (e.g. memory, storage, web...)

func AsTerminal

func AsTerminal[IN any](fun TerminalFunc[IN], opts ...Option) *Terminal[IN]

AsTerminal wraps a TerminalFunc into a Terminal node.

func (*Terminal[IN]) Done

func (t *Terminal[IN]) Done() <-chan struct{}

Done returns a channel that is closed when the Terminal node has ended its processing. This is, when all its inputs have been also closed. Waiting for all the Terminal nodes to finish allows blocking the execution until all the data in the graph has been processed and all the previous stages have ended

func (*Terminal[IN]) InType

func (m *Terminal[IN]) InType() reflect.Type

type TerminalFunc

type TerminalFunc[IN any] func(out <-chan IN)

TerminalFunc is a function that receives a readable channel as unique argument. It must process the inputs from the input channel until it's closed.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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