1
0
mirror of https://github.com/go-task/task.git synced 2024-12-14 10:52:43 +02:00
task/cyclic.go

30 lines
597 B
Go
Raw Normal View History

package task
2017-04-24 15:25:38 +02:00
// HasCyclicDep checks if a task tree has any cyclic dependency
func (e *Executor) HasCyclicDep() bool {
visits := make(map[string]struct{}, len(e.Tasks))
var checkCyclicDep func(string, *Task) bool
checkCyclicDep = func(name string, t *Task) bool {
if _, ok := visits[name]; ok {
return false
}
visits[name] = struct{}{}
defer delete(visits, name)
for _, d := range t.Deps {
2017-07-02 20:30:50 +02:00
if !checkCyclicDep(d.Task, e.Tasks[d.Task]) {
return false
}
}
return true
}
for k, v := range e.Tasks {
if !checkCyclicDep(k, v) {
return true
}
}
return false
}