Skip to content

Commit

Permalink
feat: taskfile mutex for adding edge data
Browse files Browse the repository at this point in the history
  • Loading branch information
pd93 committed Apr 24, 2024
1 parent 53235f0 commit f75aa1f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions taskfile/ast/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package ast
import (
"fmt"
"os"
"sync"

"github.com/dominikbraun/graph"
"github.com/dominikbraun/graph/draw"
"golang.org/x/sync/errgroup"
)

type TaskfileGraph struct {
sync.Mutex
graph.Graph[string, *TaskfileVertex]
}

Expand All @@ -25,6 +27,7 @@ func taskfileHash(vertex *TaskfileVertex) string {

func NewTaskfileGraph() *TaskfileGraph {
return &TaskfileGraph{
sync.Mutex{},
graph.New(taskfileHash,
graph.Directed(),
graph.PreventCycles(),
Expand Down
2 changes: 2 additions & 0 deletions taskfile/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f75aa1f

Please sign in to comment.