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

fsm.Event(ctx, ...) not work properly with context.WithTimeout() #90

Open
qiulin opened this issue Aug 19, 2022 · 2 comments
Open

fsm.Event(ctx, ...) not work properly with context.WithTimeout() #90

qiulin opened this issue Aug 19, 2022 · 2 comments

Comments

@qiulin
Copy link

qiulin commented Aug 19, 2022

When I use context.WithTimeout(ctx, time.Duration) with fsm.Event(ctx, ...) like:

Callbacks{
			"enter_end": func(ctx context.Context, e *Event) {
				go func() {
					<-ctx.Done()
					enterEndAsyncWorkDone = true
				}()
			},
		},

the internal block exec immediately, not after timeout.

@annismckenzie
Copy link
Contributor

Interesting use case. I'll take a look at this. Are you constructing an FSM on the fly? A bit of pseudo code would help.

@annismckenzie
Copy link
Contributor

This is possible. You'll need to make the callback async. The example in https://github.com/looplab/fsm/blob/main/examples/cancel_async_transition.go shows how to use this. That example is geared towards canceling the transition but you can just as easily block on your timeout context and then decide what to do (cancel the transition, trigger an event on the state machine).

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

No branches or pull requests

2 participants