How can I 'await' an action? #5251
Unanswered
iradkotton
asked this question in
Q&A
Replies: 1 comment
-
With state machines, the only real way, at least currently, is to do just as you described: wait until it reaches a specific state. Do you have a more full code example? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In my app there are some actions which includes validation and some async operations + they should only be called when on a certain state.
How can i
await
that action to complete?I have no control on the actor who calls these actions, meaning it can be called on each state.
So I added handling on each state that in case of an error, we have its own handling, sometimes its just logs 'invalid action for state', and sometimes its 'please wait', and in the happy path it moves to next state.
Now I want to know in the context of calling the action, if the action succeded or not, or to even return from the state machine the test of 'please wait', or 'successfully moved to next state'
These actions should be async, how can I achieve it with xstate?
so far the only thing I thought about is passing the action like this:
Which will work, but seems a bit weird for me, is there another way?
Beta Was this translation helpful? Give feedback.
All reactions