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

How to use it in web #456

Open
sachinmani opened this issue Aug 2, 2021 · 2 comments
Open

How to use it in web #456

sachinmani opened this issue Aug 2, 2021 · 2 comments

Comments

@sachinmani
Copy link

Could anyone give an example of how this tool could be used in a web api world in a more interactive where user input causing transitions

@Ephron-WL
Copy link

Your state machine would be instantiated for the user and stored in the user's session. As the user invoked web API methods, you'd call Fire methods on the state machine. The state machine would in effect maintain the state of the user's session. You could include multiple state machines, build hierarchies, or approximately orthogonal relationships, all housed in the session object. The state could be persisted to storage to survive server restart or the user's session expiring and being purged from memory.

@crozone
Copy link
Collaborator

crozone commented Oct 2, 2023

To use the state machine in web scenarios where the context usually only lives for the duration of each request, I recommend using the External State Storage strategy.

While constructing the state machine, pass in lambdas that will update and retrieve some external state. This may involve updating a key in the user cookie or session, or updating a database field for the user. Every time a request comes in, the state machine can be re-constructed with the same lambdas. As long as all the state is persisted somewhere that will survive outside of the request, it doesn't matter if the actual state machine object is re-constructed for each request.

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

3 participants