Skip to content

Commit

Permalink
feat(machine): add global AnyAny negotiation handler (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
pancsta committed Jul 10, 2024
1 parent 91b3c55 commit 6bad1fa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
5 changes: 5 additions & 0 deletions pkg/machine/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2007,3 +2007,8 @@ func TestOnEventCtxDispose(t *testing.T) {
m.Dispose()
<-m.WhenDisposed()
}

// TODO TestAnyAnyHandler
func TestAnyAnyHandler(t *testing.T) {
t.Skip()
}
8 changes: 6 additions & 2 deletions pkg/machine/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,12 @@ func (e *emitter) dispose() {
// ///// exception support
// ///////////////

// Exception is the Exception state name
const Exception = "Exception"
const (
// Exception is a name the Exception state.
Exception = "Exception"
// Any is a name of a meta state used in catch-all handlers.
Any = "Any"
)

// ExceptionArgsPanic is an optional argument ["panic"] for the Exception state
// which describes a panic within a Transition handler.
Expand Down
11 changes: 9 additions & 2 deletions pkg/machine/transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func (t *Transition) emitEnterEvents() Result {
// isCalled := slices.Contains(t.CalledStates(), toState)
args := t.Mutation.Args

ret := t.emitHandler("Any", toState, "Any"+toState, args)
ret := t.emitHandler(Any, toState, Any+toState, args)
if ret == Canceled {
return ret
}
Expand All @@ -291,7 +291,7 @@ func (t *Transition) emitExitEvents() Result {
return ret
}
}
ret = t.emitHandler(from, "Any", from+"Any", nil)
ret = t.emitHandler(from, Any, from+Any, nil)
if ret == Canceled {
return ret
}
Expand Down Expand Up @@ -354,6 +354,7 @@ func (t *Transition) emitEvents() Result {
m.emit(EventTransitionStart, txArgs, nil)

// NEGOTIATION CALLS PHASE (cancellable)

// FooFoo handlers
if result != Canceled && t.Type() != MutationRemove {
result = t.emitSelfEvents()
Expand All @@ -369,6 +370,12 @@ func (t *Transition) emitEvents() Result {
result = t.emitEnterEvents()
}

// global AnyAny handler
ret := t.emitHandler(Any, Any, Any+Any, t.Mutation.Args)
if ret == Canceled {
return ret
}

// FINAL HANDLERS (non cancellable)
if result != Canceled {

Expand Down

0 comments on commit 6bad1fa

Please sign in to comment.