Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Passing data / input / output between States (Workflow automation use case) #468

Unanswered
sevetseh28 asked this question in Q&A
Discussion options

Hi! I've started to use this lib for a project because it seems very packed for what I'd like to do: simple Workflow execution.
But I couldn't find in the docs a clear explanation of how to handle data passing or sharing between states which seems basic compared to what the library offers, that's why I find it strange I couldn't easily find it. As an example, I'd like to make sure that before transitioning into a specific state, certain data is being passed so that further States / Transitions that depend on that data can proceed. Thank you!

You must be logged in to vote

Replies: 1 comment 2 replies

Comment options

Hi @sevetseh28,

How are you?

Could you provide a concrete or even a toy example? I'm unsure if you're asking about passing information in an event for use in actions or storing additional data that can be used later.

There is an example of a Guess the Number Machine where the number of guesses is stored in the state machine instance, and the attempt number is passed as a positional argument into the guess event trigger.

In this example, the state machine is attached to a dataclass. Notice how we pass a token in the signup event trigger.

Let me know if this helps.

Best regards!

You must be logged in to vote
2 replies
Comment options

Hey Fernando :)

Thanks for the quick reply. My use case is basically a Workflow execution , so it's just a subset of a State machine, or a special case of a State machine. My workflow is pretty linear with only a few branchings based on certain conditions.

And as with any Workflow execution, my Nodes (states) will receive an input from the previous node, and pass an output to the next Node. I'd like to type these with strict type hints to have a clear contract between the States and let MyPy catch these.

I'm not currently with my machine but can write an example once I Get back to it.

So you suggest using the event methods to pass my own arguments ? I think that may work.

Thanks !

Comment options

One thing that I didn't mention is that I'd also like my workflow to run automatically (i.e. execute some kind of .run method and just let it start the execution and resolve which transitions it will go to based on the conditions defined and I couldn't see what is the best practice for this. Should the State themselves send an event? from the examples I always saw an external caller explicitly call an event.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /