Skip to content

Commit

Permalink
Merge pull request #50 from qmuntal/dynerr
Browse files Browse the repository at this point in the history
Return error from PermitDynamic
  • Loading branch information
qmuntal committed Jul 24, 2022
2 parents 491b438 + 065696c commit cc05e41
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
7 changes: 3 additions & 4 deletions statemachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,9 @@ func (sm *StateMachine) internalFireOne(ctx context.Context, trigger Trigger, ar
transition := Transition{Source: source, Destination: t.Destination, Trigger: trigger}
err = sm.handleReentryTrigger(ctx, representativeState, transition, args...)
case *dynamicTriggerBehaviour:
destination, ok := t.ResultsInTransitionFrom(ctx, source, args...)
if !ok {
err = fmt.Errorf("stateless: Dynamic handler for trigger %v in state %v has failed", trigger, source)
} else {
var destination interface{}
destination, err = t.Destination(ctx, args...)
if err == nil {
transition := Transition{Source: source, Destination: destination, Trigger: trigger}
err = sm.handleTransitioningTrigger(ctx, representativeState, transition, args...)
}
Expand Down
9 changes: 0 additions & 9 deletions triggers.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,6 @@ type dynamicTriggerBehaviour struct {
Destination func(context.Context, ...interface{}) (State, error)
}

func (t *dynamicTriggerBehaviour) ResultsInTransitionFrom(ctx context.Context, _ State, args ...interface{}) (st State, ok bool) {
var err error
st, err = t.Destination(ctx, args...)
if err == nil {
ok = true
}
return
}

type internalTriggerBehaviour struct {
baseTriggerBehaviour
Action ActionFunc
Expand Down

0 comments on commit cc05e41

Please sign in to comment.