dependency

package
v0.1.16 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2021 License: BSD-3-Clause Imports: 2 Imported by: 0

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

View Source
var ErrNotFound = 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 NewGraph

func NewGraph() *Graph

NewGraph returns a new Graph ready to be used.

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.

func (*Graph) Depend

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.

Jump to

Keyboard shortcuts

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