Skip to content

Latest commit

 

History

History
50 lines (34 loc) · 752 Bytes

README.md

File metadata and controls

50 lines (34 loc) · 752 Bytes

dag

This is a slightly modified version of the Terraform dag code with the Terraform dependencies removed.

Example

package main

import (
	"fmt"
	"time"

	"github.com/silas/dag"
)

func main() {
	g := &dag.AcyclicGraph{}

	p := "<complete>"

	g.Add(p)

	g.Add("a")
	g.Connect(dag.BasicEdge(p, "a"))

	g.Add("b")
	g.Connect(dag.BasicEdge(p, "b"))
	g.Connect(dag.BasicEdge("b", "a"))

	g.Add("c")
	g.Connect(dag.BasicEdge(p, "c"))
	g.Connect(dag.BasicEdge("c", "a"))

	if err := g.Validate(); err != nil {
		panic(err)
	}

	g.Walk(func(v dag.Vertex) (d dag.Diagnostics) {
		key := v.(string)

		fmt.Println(key)
		time.Sleep(2 * time.Second)

		return
	})
}