qmuntal / stateless

Go library for creating finite state machines

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Concurrent issue on String() function

youngSSS opened this issue · comments

When calling String() concurrently, it goes to panic.
Is it possible to use sync.Map to avoid panic?

func (sm *StateMachine) stateRepresentation(state State) (sr *stateRepresentation) {
	var ok bool
	if sr, ok = sm.stateConfig[state]; !ok {
		sr = newstateRepresentation(state)
		sm.stateConfig[state] = sr // concurrent panic point
	}
	return
}

Thanks for reporting, will fix soon.