Documentation ¶
Overview ¶
Package dependency keeps track of a dependency graph. You add edges to the graph by specifying an object and the objects it depends on. You can then call FinsihAndWait when the object is finished to wait until all the dependents are also finished.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var NotFoundError = fmt.Errorf(
"Attempting to create an object whose dependency has already been terminated.")
Functions ¶
This section is empty.
Types ¶
type Graph ¶
type Graph struct {
// contains filtered or unexported fields
}
Graph keeps track of a number of objects and their dependents. Typical usage looks like:
g := NewGraph()
// Instruct the graph that A depends on B and C.
if err := g.Depend(A, B, C); err != nil { // Oops, B or C is already terminating, clean up A immediately. }
// D depends on A (You should check the error as above). g.Depend(D, A) ... // At some point we want to mark A as closed to new users and // wait for all the objects that depend on it to finish // (in this case D). finish := g.CloseAndWait(A) // Now we know D (and any other depdendents) are finished, so we // can clean up A. A.CleanUp() // Now notify the objects A depended on that they have one less // dependent. finish()
func (*Graph) CloseAndWait ¶
func (g *Graph) CloseAndWait(obj interface{}) func()
CloseAndWait closes an object to new dependents and waits for all dependants to complete. When this function returns you can safely clean up Obj knowing that no users remain. Once obj is finished with the objects it depends on, you should call the returned function.
func (*Graph) CloseAndWaitForAll ¶
func (g *Graph) CloseAndWaitForAll()
CloseAndWaitForAll closes the graph. No new objects or dependencies can be added and this function returns only after all existing objects have called Finish on their finishers.