-
I'm quite new to statecharts and this library, so I'm not sure if this is the best way to model what I'm trying to do. Basically I need to model a situation where I'm waiting for a specific reply from an external source. Before sending this reply, the external source might (but not necessarily need to) request some information from me. I want to be able to respond to these requests, but only while waiting for the reply. And the compound state should not be done while either the reply is missing or we're currently responding. My first thought was using two parallel states:
Is is possible to model this behavior using final states? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
Given your described requirements I've come up with this, quite simple, solution: processing: {
invoke: {
id: 'external_service'
src: externalSource,
},
states: {
waiting: {
on: {
ASKED_FOR_DATA: {
actions: respond((ctx) => ({ type: 'DATA_RESPONSE', data: ctx.foo }))
},
RESPONSE_RECEIVED: 'done'
}
},
done: {
type: 'final'
}
}
} |
Beta Was this translation helpful? Give feedback.
-
I've played around in the visualizer and this does seem to work. However, I'm not sure if this is intended behavior that I can rely on.
|
Beta Was this translation helpful? Give feedback.
-
There is quite a lot to digest here - so I could have easily missed something, but let me answer to some parts of your problem and if it still won't be enough then we'll just continue iterating over this.
|
Beta Was this translation helpful? Give feedback.
-
If you put it like this, the simple command is just a subset of the more complicated one, yes. I tried to reformulate the requirements and steps, hope its easier to grasp this way.
Additionally, I need to retry the entire procedure in the sendData case in the following cases:
These two points currently cause me headaches:
|
Beta Was this translation helpful? Give feedback.
I've played around in the visualizer and this does seem to work. However, I'm not sure if this is intended behavior that I can rely on.