node

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2022 License: Apache-2.0 Imports: 3 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 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) 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) *Middle

AsMiddle wraps an MiddleFunc into an Middle node. It panics if the MiddleFunc does not follow the func(<-chan,chan<-) signature.

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 {
	// 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(...Receiver)
}

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) *Terminal

AsTerminal wraps a TerminalFunc into a Terminal node. 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

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