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 Init ¶
type Init[OUT any] struct { // contains filtered or unexported fields }
Init 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 Init node. An Init node must have at least one output node.
type InitFunc ¶
type InitFunc[OUT any] func(out chan<- OUT)
InitFunc is a function that receives a writable channel as unique argument, and sends value to that channel during an indefinite amount of time.
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]) *Middle[IN, OUT]
AsMiddle wraps an MiddleFunc into an Middle node.
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 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.Init and node.Middle
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]) *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
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.