Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can FSM.Transaction() accept a parameter to cancel the asynchronous transaction? #76

Open
suerta-git opened this issue Sep 27, 2021 · 2 comments

Comments

@suerta-git
Copy link

As far as I know, after I triggered an asynchronous event, the only thing I can do is calling FSM.Transaction() to finish its transaction.

sm := fsm.NewFSM(
	"start",
	fsm.Events{
		{Name: "start", Src: []string{"start"}, Dst: "end"},
	},
	fsm.Callbacks{
		"leave_start": func(e *fsm.Event) {
			e.Async()
		},
	},
)

_ = sm.Event("start")    //  Return immediately

// Do my own business

// It's impossible to cancel the event at this time
_ = sm.Transaction()    //  Only can finish transaction

Currently there is no way to interrupt an asynchronous transaction on demand, right?

So I suppose maybe Transaction() method can accept a parameter to cancel the execution.

@suerta-git
Copy link
Author

Or a new method is ok

@annismckenzie
Copy link
Contributor

With #88 merged this is now possible. You can take a look at the relevant example: https://github.com/looplab/fsm/blob/main/examples/cancel_async_transition.go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants