Skip to content

Commit

Permalink
Preparing to publish on pkg.go.dev
Browse files Browse the repository at this point in the history
  • Loading branch information
astavonin committed Nov 24, 2024
1 parent 79edd87 commit e728400
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ go.work

# stringer generated files
*_string.go

# OS-specific
.DS_Store
22 changes: 11 additions & 11 deletions examples/two-phase-commit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"gfsm/pkg/gfsm"
gfsm2 "github.com/astavonin/gfsm"
)

//go:generate stringer -type=State
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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")
Expand All @@ -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}).
Expand Down
1 change: 1 addition & 0 deletions pkg/gfsm/gfsm.go → gfsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module gfsm
module github.com/astavonin/gfsm

go 1.23

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit e728400

Please sign in to comment.