graph
Simple graph with a parallel node walker
Usage
A graph is constructed using a series of linkers, each linker containing a single node. Each linker by default has one input and one output connector, which might be used to connect to other linkers:
linker1.Link(linker1)
or
linker1.Connect(linker2, linker1.Connector(graph.InputName), linker2.Connector(graph.OutputName, graph.OutputType))
Once a chain has been finalized, a starting linker can be selected to act as the first root to be used when walking over the graph. This root can be used to create a walker, which upon creation will find any other roots in the graph, and calculate the total number of nodes in it. Walking the graph will produce a channel, which will emit a new item for each node. Any processing of these items can be done concurrently, since nodes will wait for their dependencies to finish processing. The user has to notify the walker by closing the item once processing has finished. Once all nodes have been walked, the channel will be closed.
w := graph.NewWalker(root)
for wd := range w.Walk() {
go func(wd graph.WalkData) {
defer wd.Close()
// Do whatever operation can be identified by the current node
}(wd)
}
A complete example can be read here