v.io: v.io/x/ref/runtime/internal/lib/dependency Index | Files

package dependency

import "v.io/x/ref/runtime/internal/lib/dependency"

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.


Package Files



var ErrNotFound = fmt.Errorf(
    "attempting to create an object whose dependency has already been terminated")

type Graph Uses

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 NewGraph Uses

func NewGraph() *Graph

NewGraph returns a new Graph ready to be used.

func (*Graph) CloseAndWait Uses

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 Uses

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.

func (*Graph) Depend Uses

func (g *Graph) Depend(obj interface{}, on ...interface{}) error

Depend adds obj as a node in the dependency graph and notes it's dependencies on all the objects in 'on'. If any of the dependencies are already closed (or are not in the graph at all) then Depend returns ErrNotFound and does not add any edges.

Package dependency imports 2 packages (graph) and is imported by 5 packages. Updated 2020-10-22. Refresh now. Tools for package owners.