diff --git a/.gitignore b/.gitignore index 23fa4e7..4dbbcf2 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,6 @@ go.work # stringer generated files *_string.go + +# OS-specific +.DS_Store diff --git a/examples/two-phase-commit/main.go b/examples/two-phase-commit/main.go index 4dc4d59..eec08d4 100644 --- a/examples/two-phase-commit/main.go +++ b/examples/two-phase-commit/main.go @@ -2,7 +2,7 @@ package main import ( "fmt" - "gfsm/pkg/gfsm" + gfsm2 "github.com/astavonin/gfsm" ) //go:generate stringer -type=State @@ -28,13 +28,13 @@ type commitRequest struct { commitID string } -func (s *initState) OnEnter(_ gfsm.StateMachineContext) { +func (s *initState) OnEnter(_ gfsm2.StateMachineContext) { } -func (s *initState) OnExit(_ gfsm.StateMachineContext) { +func (s *initState) OnExit(_ gfsm2.StateMachineContext) { } -func (s *initState) Execute(smCtx gfsm.StateMachineContext, eventCtx gfsm.EventContext) State { +func (s *initState) Execute(smCtx gfsm2.StateMachineContext, eventCtx gfsm2.EventContext) State { cCtx := smCtx.(*coordinatorContext) req, ok := eventCtx.(commitRequest) if !ok { @@ -64,14 +64,14 @@ type commitVote struct { commit bool } -func (s *waitState) OnEnter(_ gfsm.StateMachineContext) { +func (s *waitState) OnEnter(_ gfsm2.StateMachineContext) { s.votesCnt = 0 } -func (s *waitState) OnExit(_ gfsm.StateMachineContext) { +func (s *waitState) OnExit(_ gfsm2.StateMachineContext) { } -func (s *waitState) Execute(smCtx gfsm.StateMachineContext, eventCtx gfsm.EventContext) State { +func (s *waitState) Execute(smCtx gfsm2.StateMachineContext, eventCtx gfsm2.EventContext) State { cCtx := smCtx.(*coordinatorContext) vote, ok := eventCtx.(commitVote) if !ok || !vote.commit { @@ -98,7 +98,7 @@ type responseState struct { keepResp State } -func (s *responseState) OnEnter(smCtx gfsm.StateMachineContext) { +func (s *responseState) OnEnter(smCtx gfsm2.StateMachineContext) { cCtx := smCtx.(*coordinatorContext) s.votesCnt = cCtx.partCnt fmt.Printf("commiting %s\n", cCtx.commitID) @@ -107,10 +107,10 @@ func (s *responseState) OnEnter(smCtx gfsm.StateMachineContext) { //} } -func (s *responseState) OnExit(_ gfsm.StateMachineContext) { +func (s *responseState) OnExit(_ gfsm2.StateMachineContext) { } -func (s *responseState) Execute(_ gfsm.StateMachineContext, eventCtx gfsm.EventContext) State { +func (s *responseState) Execute(_ gfsm2.StateMachineContext, eventCtx gfsm2.EventContext) State { resp, ok := eventCtx.(commitVote) if !ok { fmt.Printf("invalid responce\n") @@ -132,7 +132,7 @@ func (s *responseState) Execute(_ gfsm.StateMachineContext, eventCtx gfsm.EventC } func main() { - sm := gfsm.NewBuilder[State](). + sm := gfsm2.NewBuilder[State](). SetDefaultState(Init). SetSmContext(&coordinatorContext{partCnt: 3}). RegisterState(Init, &initState{}, []State{Wait}). diff --git a/pkg/gfsm/gfsm.go b/gfsm.go similarity index 99% rename from pkg/gfsm/gfsm.go rename to gfsm.go index 77d950f..a6b2a03 100644 --- a/pkg/gfsm/gfsm.go +++ b/gfsm.go @@ -27,6 +27,7 @@ type StateMachineHandler[StateIdentifier comparable] interface { // On Start call, state machine will switch to the defined default state, which must be specified during state // machine creation using StateMachineBuilder.SetDefaultState(...) call Start() + // Stop call shutdowns the state machine. Any further State or ProcessEvent are not permitted on stopped // state machine. Stop() diff --git a/pkg/gfsm/gfsm_test.go b/gfsm_test.go similarity index 100% rename from pkg/gfsm/gfsm_test.go rename to gfsm_test.go diff --git a/go.mod b/go.mod index 535ad53..0deedb1 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module gfsm +module github.com/astavonin/gfsm go 1.23 diff --git a/pkg/gfsm/perf_test.go b/perf_test.go similarity index 100% rename from pkg/gfsm/perf_test.go rename to perf_test.go diff --git a/pkg/gfsm/sm_builder.go b/sm_builder.go similarity index 100% rename from pkg/gfsm/sm_builder.go rename to sm_builder.go diff --git a/pkg/gfsm/state_action.go b/state_action.go similarity index 100% rename from pkg/gfsm/state_action.go rename to state_action.go