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

Allow sending events from within an FSM state function #1664

Closed
7 tasks done
alecthomas opened this issue Jun 5, 2024 · 1 comment · Fixed by #1723
Closed
7 tasks done

Allow sending events from within an FSM state function #1664

alecthomas opened this issue Jun 5, 2024 · 1 comment · Fixed by #1723
Assignees

Comments

@alecthomas
Copy link
Collaborator

alecthomas commented Jun 5, 2024

Currently, sending an event to an FSM while the FSM is transitioning is invalid. However, sometimes the state itself knows what the next state should be.

We could either allow Send() to be used in this fashion directly, or add a new method Next() that fulfils this need.

@alecthomas alecthomas self-assigned this Jun 5, 2024
@ftl-robot ftl-robot mentioned this issue Jun 5, 2024
@matt2e
Copy link
Collaborator

matt2e commented Jul 10, 2024

Confirmed with Moe, this is not a blocker for the current deadline anymore, they are using pub sub instead of FSM to get around this.

@alecthomas alecthomas assigned matt2e and unassigned alecthomas Aug 8, 2024
github-merge-queue bot pushed a commit that referenced this issue Aug 15, 2024
closes #1664
closes #2334

This is particularly useful when an FSM state itself knows which state
it should be in next, for example transitioning a payment to "voided" if
an error occurs communicating with an external vendor.

- Adds `fsm.Next(ctx, event)` to the go runtime
    - Only one next transition is allowed per fsm instance
- When a transition completes, the next transition is queued up if it
exists
- When a transition returns an error, we wipe the next transition so
that the retry attempt can set the next transition again

In another PR we will move away from using `ftl.Next()` to avoid the
reference cycle issue.

---------

Co-authored-by: Matt Toohey <[email protected]>
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

Successfully merging a pull request may close this issue.

2 participants