fsm icon indicating copy to clipboard operation
fsm copied to clipboard

Is it one redundant code?

Open falconray0704 opened this issue 5 years ago • 0 comments

Hi, Firstly, thanks for you work, it's a great job. I have one question in the following code: *In fsm.go line:324 function: func (f FSM) Event(event string, args ...interface{}) error

// Perform the rest of the transition, if not asynchronous. f.stateMu.RUnlock() err = f.doTransition() f.stateMu.RLock() if err != nil { return InternalError{} }

Per the comment in line:319 "// Perform the rest of the transition, if not asynchronous.". I think that means in sync mode would run the following code. So, InternalError{} should come from f.doTransition()

But, In function: // doTransition wraps transitioner.transition. func (f *FSM) doTransition() error { return f.transitionerObj.transition(f) }

"f.transitionerObj" is "transitionerStruct"

Then transitionerStruct's transition() should be called.

But In this function, the only way return error is "f.transition == nil" func (t transitionerStruct) transition(f *FSM) error { if f.transition == nil { return NotInTransitionError{} } f.transition() f.transition = nil return nil }

But, per the previous code, if "f.doTransition()" can be invoked, "f.transition" have no way to get nil.

Is it one redundant code? I'm confuse, I hope I could get your help to confirm did I miss something or not.

falconray0704 avatar Mar 19 '19 10:03 falconray0704