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

Please add the ability to reuse a state machine #79

Open
scr-oath opened this issue Jul 2, 2024 · 5 comments
Open

Please add the ability to reuse a state machine #79

scr-oath opened this issue Jul 2, 2024 · 5 comments

Comments

@scr-oath
Copy link

scr-oath commented Jul 2, 2024

I would like to use a state machine for a complicated logic flow for every request of a server - mainly to self-document (the graphviz stuff) and it would be really nice to make a new state machine from an existing archetype of sorts. Merely cloning one in its initial state would be great!

@scr-oath
Copy link
Author

scr-oath commented Jul 2, 2024

If you're feeling really creative, you could make an interface for a state machine instance and keep a pointer to the machine and just the state can be copied to a new instance

@scr-oath scr-oath changed the title Please add the ability to clone a state machine. Please add the ability to reuse a state machine Jul 3, 2024
@scr-oath
Copy link
Author

scr-oath commented Jul 3, 2024

Another idea - is to provide a very fast reset call and use sync.Pool to "reuse"

@qmuntal
Copy link
Owner

qmuntal commented Jul 8, 2024

Hmm, I'm not sure I understand your request. You can already instantiate a new state machine with a custom initial state using stateless.NewStateMachine, and that initial state can be retrieved from an existing instance using StateMachine.State. Would that work for you?

@jhberges
Copy link

jhberges commented Jul 9, 2024

I read the need here as "scaffolding", though I might easily be mistaken. :-)

In that case I'd go for VS Code snippets (if using VS Code), or something like https://yeoman.io/ if the requirement is more for a "distributed team" setup.

@scr-oath
Copy link
Author

scr-oath commented Jul 9, 2024

Well I ended up creating a Reset trigger and stuffing into a sync.Pool for reuse. That works fine. Except that it turns the diagram into a loop. I'd love to be able just say reset to initial but there doesn't seem to be any mechanism for setting state; only firing a trigger.

What I envisioned second was somewhat inspired by the name... is there some way we could have many instances of the state and one state machine, which could be initialized once as a singleton and reused concurrently with separate state instances (or stuff the state in the context as a pointer)?

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