feat: taskfile mutex for adding edge data

This commit is contained in:
Pete Davison
2024-04-21 19:40:26 +00:00
parent 53235f07ad
commit f75aa1f84b
2 changed files with 5 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ package ast
import (
"fmt"
"os"
"sync"
"github.com/dominikbraun/graph"
"github.com/dominikbraun/graph/draw"
@@ -10,6 +11,7 @@ import (
)
type TaskfileGraph struct {
sync.Mutex
graph.Graph[string, *TaskfileVertex]
}
@@ -25,6 +27,7 @@ func taskfileHash(vertex *TaskfileVertex) string {
func NewTaskfileGraph() *TaskfileGraph {
return &TaskfileGraph{
sync.Mutex{},
graph.New(taskfileHash,
graph.Directed(),
graph.PreventCycles(),

View File

@@ -140,6 +140,8 @@ func (r *Reader) include(node Node) error {
}
// Create an edge between the Taskfiles
r.graph.Lock()
defer r.graph.Unlock()
edge, err := r.graph.Edge(node.Location(), includeNode.Location())
if err == graph.ErrEdgeNotFound {
// If the edge doesn't exist, create it