qmuntal / stateless

Go library for creating finite state machines
BSD 2-Clause "Simplified" License
898 stars 47 forks source link

Allow adding actions for leaving a state with a specific trigger #75

Closed Metamogul closed 1 month ago

Metamogul commented 2 months ago

Currently it is possible to configure states to perform an action when entering them, as well as setting a specific action when entering them from a specific transition (config.go:145):

func (sc *StateConfiguration) OnEntryFrom(trigger Trigger, action ActionFunc) *StateConfiguration {
    sc.sr.EntryActions = append(sc.sr.EntryActions, actionBehaviour{
        Action:      action,
        Description: newinvocationInfo(action),
        Trigger:     &trigger,
    })
    return sc
}

However this is not possible when leaving states with a specific transition. I propose to amend this feature.

Metamogul commented 2 months ago

@qmuntal, do you have any objections or do you see this addition not fit to meet your goals with the library? Please let me know if this PR needs changes to be added to the project.

qmuntal commented 2 months ago

Thanks for submitting this request. It does make sense, will review the PR soon.