node

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2022 License: Apache-2.0 Imports: 4 Imported by: 6

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 CreationOption added in v0.2.0

type CreationOption func(options *creationOptions)

CreationOption allows overriding the default values of node instantiation

func ChannelBufferLen added in v0.2.0

func ChannelBufferLen(length int) CreationOption

ChannelBufferLen is a node.CreationOption 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 Init

type Init 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.

func AsInit

func AsInit(fun InitFunc) *Init

AsInit wraps an InitFunc into an Init node. It panics if the InitFunc does not follow the func(chan<-) signature.

func (*Init) OutType added in v0.1.1

func (s *Init) OutType() reflect.Type

func (*Init) SendsTo

func (s *Init) SendsTo(outputs ...Receiver)

func (*Init) Start

func (i *Init) Start()

type InitFunc

type InitFunc interface{}

InitFunc is a function that receives a writable channel as unique argument, and sends value to that channel during an indefinite amount of time. TODO: with Go 1.18, this will be type InitFunc[OUT any] func(out chan<- OUT)

type Middle

type Middle 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(fun MiddleFunc, opts ...CreationOption) *Middle

AsMiddle wraps an MiddleFunc into an Middle node, allowing to configure some instantiation parameters by means of an optional list of node.CreationOption. It panics if the MiddleFunc does not follow the func(<-chan,chan<-) signature.

func (*Middle) InType added in v0.1.1

func (m *Middle) InType() reflect.Type

func (*Middle) OutType added in v0.1.1

func (m *Middle) OutType() reflect.Type

func (*Middle) SendsTo

func (s *Middle) SendsTo(outputs ...Receiver)

type MiddleFunc

type MiddleFunc interface{}

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. TODO: with Go 1.18, this will be type MiddleFunc[IN, OUT any] func(in <-chan IN, out chan<- OUT)

type Receiver

type Receiver 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 interface {
	// SendsTo connect a sender with a group of receivers
	SendsTo(...Receiver)
	// 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 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(fun TerminalFunc, opts ...CreationOption) *Terminal

AsTerminal wraps a TerminalFunc into a Terminal node, allowing to configure some instantiation parameters by means of an optional list of node.CreationOption. It panics if the TerminalFunc does not follow the func(<-chan) signature.

func (*Terminal) Done

func (t *Terminal) 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) InType added in v0.1.1

func (m *Terminal) InType() reflect.Type

type TerminalFunc

type TerminalFunc interface{}

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. TODO: with Go 1.18, this will be type TerminalFunc[IN any] func(out <-chan IN)

Jump to

Keyboard shortcuts

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