Skip to content

Commit

Permalink
Limit cycles
Browse files Browse the repository at this point in the history
  • Loading branch information
hovsep committed Sep 21, 2024
1 parent 2a27fd0 commit aab3e37
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions fmesh.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package fmesh

import (
"errors"
"github.com/hovsep/fmesh/component"
"github.com/hovsep/fmesh/cycle"
"sync"
)

// @TODO: move this to fm.Config
const maxCyclesAllowed = 100 //Dev mode

// FMesh is the functional mesh
type FMesh struct {
name string
Expand Down Expand Up @@ -112,7 +116,7 @@ func (fm *FMesh) Run() (cycle.Collection, error) {
cycleResult := fm.runCycle()
allCycles = allCycles.Add(cycleResult)

mustStop, err := fm.mustStop(cycleResult)
mustStop, err := fm.mustStop(cycleResult, len(allCycles))
if mustStop {
return allCycles, err
}
Expand All @@ -121,7 +125,11 @@ func (fm *FMesh) Run() (cycle.Collection, error) {
}
}

func (fm *FMesh) mustStop(cycleResult *cycle.Cycle) (bool, error) {
func (fm *FMesh) mustStop(cycleResult *cycle.Cycle, cycleNum int) (bool, error) {
if cycleNum >= maxCyclesAllowed {
return true, errors.New("reached max allowed cycles")

Check warning on line 130 in fmesh.go

View check run for this annotation

Codecov / codecov/patch

fmesh.go#L130

Added line #L130 was not covered by tests
}

//Check if we are done (no components activated during the cycle => all inputs are processed)
if !cycleResult.HasActivatedComponents() {
return true, nil
Expand Down

0 comments on commit aab3e37

Please sign in to comment.