Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Background ¶
type Background struct { Ctx context.Context // background context Err chan<- error // write-only error channel }
Flow's background, which defines its timed context and a global error channel.
type Flow ¶
type Flow struct { Conn map[string]chan interface{} // edge name -> channel Nodes map[string]*Node // node name -> node Start *Node // super start node, not in Nodes map TOut time.Duration // timeout definition Done chan interface{} // done channel, named as "Done" }
A flow is defined as: A map for all connections / edges; a map for all nodes; a super start node, which is regarded as flow's switch; a timeout duration, which defines max running time for the flow; and a Done channel, which indicate the flow is completed or not by using a bool value.
func (*Flow) Connect ¶
Connect two nodes in the flow. Channel will be named as {n1.Name}2{n2.Name} to indicate the direction.
func (*Flow) InitSink ¶
Init sink node. It will be added to flow.Nodes map. This is a special node, which has an output pointing to flow's Done channel (aka. super sink node).
type Node ¶
type Node struct { Name string // node name, cannot be empty Ps *Ports // node's interfaces Tk func() error // node's job Bg *Background // background, cannot be nil }
Each node in the flow must have an unique name. It is used for labeled the connections / edges. The main task is defined in Tk function, which take Ps ports as input and output. In order to better control the task, user should pass in the flow's background.
func NewNode ¶
Return a new node with specified unique name, which should not be nil or empty string. It will help user to initialize ports too. Note that, 1) user should define its background and function task before using it; 2) "SUPER_SINK_NODE" is a special reserved name.
func (*Node) Run ¶
func (n *Node) Run()
Run the task defined in Node.Tk function. Normally, it should be called by flow.Run(), if this node is joined in the flow.