node

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: Apache-2.0 Imports: 4 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. Deprecated package. Use github.com/mariomac/pipes/pipe package

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DemuxGet added in v0.9.0

func DemuxGet[OUT any](d Demux, key any) chan<- OUT

DemuxGet returns the output channel associated to the given key in the provided Demux. This function needs to be invoked inside a StartDemuxFunc or MiddleDemuxFunc. The function will panic if no output channel has been previously defined at build time for that given key (using the DemuxAdd) function. Experimental API. Some names could change in the following versions.

func DoneAll added in v0.10.0

func DoneAll(termNodes ...Doner) <-chan struct{}

DoneAll is a helper function returns a channel that is closed after all the passed Terminal nodes are done Deprecated package. Use github.com/mariomac/pipes/pipe package

func StartAll added in v0.10.0

func StartAll(startNodes ...Starter)

StartAll is a helper function to start in background all the Start nodes of a given pipeline Deprecated package. Use github.com/mariomac/pipes/pipe package

Types

type Bypass added in v0.10.0

type Bypass[INOUT any] struct {
	// contains filtered or unexported fields
}

Bypass node just makes sure, at graph construction time, that the inputs of this node are bypassed to the destination nodes. At a logical level, you can see a Bypass node as a Middle[T, T] node that just forwards its input to the output channel. At an implementation level, Bypass[T] is much more efficient because it just makes sure that its input channel is connected to its destination nodes, without adding any extra goroutine nor channel operation. Bypass is useful for implementing constructors that might return an optional Middle[T, T] node (according to e.g. the user configuration) or just a Bypass[T] node to transparently forward data to the destination nodes. Deprecated package. Use github.com/mariomac/pipes/pipe package

func (*Bypass[INOUT]) InType added in v0.10.0

func (b *Bypass[INOUT]) InType() reflect.Type

func (*Bypass[INOUT]) OutType added in v0.10.0

func (b *Bypass[INOUT]) OutType() reflect.Type

func (*Bypass[INOUT]) SendTo added in v0.10.0

func (b *Bypass[INOUT]) SendTo(r ...Receiver[INOUT])

type Demux added in v0.9.0

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

Demux is a collection of multiple output channels for a Demuxed node, which receives them as a second argument in its StartDemuxFunc or MiddleDemuxFunc functions. During the graph definition time, multiple outputs can be associated to a node by means of the DemuxAdd function. At runtime, you can access the multiple named output channels by means of the DemuxGet function. Experimental API. Some names could change in the following versions.

type Demuxed added in v0.9.0

type Demuxed interface {
	// contains filtered or unexported methods
}

Demuxed node whose output is not a channel but a Demux. Can be both StartDemux or MiddleDemux nodes Experimental API. Some names could change in the following versions. Deprecated package. Use github.com/mariomac/pipes/pipe package

type Doner added in v0.10.0

type Doner interface {
	Done() <-chan struct{}
}

Doner abstracts any Terminal node Deprecated package. Use github.com/mariomac/pipes/pipe package

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. Deprecated package. Use github.com/mariomac/pipes/pipe package

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 (mn *Middle[IN, OUT]) InType() reflect.Type

func (*Middle[IN, OUT]) OutType

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

func (*Middle[IN, OUT]) SendTo added in v0.8.0

func (mn *Middle[IN, OUT]) SendTo(outputs ...Receiver[OUT])

type MiddleDemux added in v0.9.0

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

MiddleDemux is any intermediate node that receives data from another node, processes/filters it, and forwards the data any of the output channels in the provided Demux. An MiddleDemux node must have at least one output node. Experimental API. Some names could change in the following versions.

func AsMiddleDemux added in v0.9.0

func AsMiddleDemux[IN any](fun MiddleDemuxFunc[IN], opts ...Option) *MiddleDemux[IN]

AsMiddleDemux wraps an MiddleDemuxFunc into an MiddleDemux node. Experimental API. Some names could change in the following versions.

func (*MiddleDemux[IN]) InType added in v0.9.0

func (md *MiddleDemux[IN]) InType() reflect.Type

type MiddleDemuxFunc added in v0.9.0

type MiddleDemuxFunc[IN any] func(in <-chan IN, out Demux)

MiddleDemuxFunc is a function that receives a readable channel as first argument, and a Demux as second argument. It must process the inputs from the input channel until it's closed and usually forward the processed values to any of the Demux output channels (previously accessed by the DemuxGet function). Experimental API. Some names could change in the following versions.

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. Deprecated package. Use github.com/mariomac/pipes/pipe package

type Option added in v0.3.0

type Option func(options *creationOptions)

Option allows overriding the default values of node instantiation Deprecated package. Use github.com/mariomac/pipes/pipe package

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. Deprecated package. Use github.com/mariomac/pipes/pipe package

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.Bypass, node.Middle and node.Terminal Deprecated package. Use github.com/mariomac/pipes/pipe package

type Sender

type Sender[OUT any] interface {
	// SendTo connect a sender with a group of receivers
	SendTo(...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, node.Middle and node.Bypass Deprecated package. Use github.com/mariomac/pipes/pipe package

func DemuxAdd added in v0.9.0

func DemuxAdd[OUT any](d Demuxed, key any) Sender[OUT]

DemuxAdd is used during the graph definition/construction time. It allows associating multiple output paths to a Demuxed node (which can be StartDemux or MiddleDemux). It returns a Sender output that can be connected to a group of output nodes for that path. The Sender created output is identified by a key that can be any value of any type, and can be later accessed from inside the node's StartDemuxFunc or MiddleDemuxFunc with the DemuxGet function. Experimental API. Some names could change in the following versions.

type SenderReceiver added in v0.10.0

type SenderReceiver[IN, OUT any] interface {
	Receiver[IN]
	Sender[OUT]
}

SenderReceiver is any node that can both send and receive data: node.Bypass or node.Middle. Deprecated package. Use github.com/mariomac/pipes/pipe package

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 or StartDemux node. An Start node must have at least one output node. Deprecated package. Use github.com/mariomac/pipes/pipe package

func AsStart added in v0.4.0

func AsStart[OUT any](funs ...StartFunc[OUT]) *Start[OUT]

AsStart wraps a group of StartFunc with the same signature into a Start node.

func (*Start) OutType added in v0.4.0

func (rg *Start) OutType() reflect.Type

OutType is the common input type of the receivers (output of the receiver group)

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

func (sn *Start[OUT]) SendTo(outputs ...Receiver[OUT])

SendTo connects a group of receivers to the current receiverGroup

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

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

Start starts the function wrapped in the Start node. This method should be invoked for all the start nodes of the same graph, so the graph can properly start and finish. Deprecated package. Use github.com/mariomac/pipes/pipe package

func (*Start) StartReceivers added in v0.9.0

func (rg *Start) StartReceivers() (*connect.Forker[OUT], error)

StartReceivers start the receivers and return a connection forker to them

type StartDemux added in v0.9.0

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

StartDemux is equivalent to a Start node, but receiving a Demux instead of a writable channel. 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 or StartDemux node. A StartDemux node must have at least one output node. Experimental API. Some names could change in the following versions.

func AsStartDemux added in v0.9.0

func AsStartDemux(funs ...StartDemuxFunc) *StartDemux

AsStartDemux wraps a group of StartDemuxFunc into a StartDemux node.

func (*StartDemux) Start added in v0.9.0

func (i *StartDemux) Start()

Start starts the function wrapped in the StartDemux node. This method should be invoked for all the start nodes of the same graph, so the graph can properly start and finish.

type StartDemuxFunc added in v0.9.0

type StartDemuxFunc func(out Demux)

StartDemuxFunc is a function that receives a Demux as unique argument, and sends, during an indefinite amount of time, values to the channels contained in the Demux (previously accessed by the DemuxGet function). Experimental API. Some names could change in the following versions. Deprecated package. Use github.com/mariomac/pipes/pipe package

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. Deprecated package. Use github.com/mariomac/pipes/pipe package

type Starter added in v0.10.0

type Starter interface {
	Start()
}

Starter abstracts any Start node Deprecated package. Use github.com/mariomac/pipes/pipe package

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...) Deprecated package. Use github.com/mariomac/pipes/pipe package

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 (tn *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 Deprecated package. Use github.com/mariomac/pipes/pipe package

func (*Terminal[IN]) InType

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

type TerminalFunc

type TerminalFunc[IN any] func(in <-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. Deprecated package. Use github.com/mariomac/pipes/pipe package

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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