Reputation: 2262
I am trying to build a DSL for my iOS project.
For this I plan to build a Semantic Model
in a form of a State Machine
. (The terminology is from Fowler's book on DSLs).
The main idea: State Machine
is coded as the set of states
and transitions
between them, and then some unit tests can be written to check if some_action
on some_state1
leads the system to a some_state2
.
The problem is my app has a lot of background threads, so more than one state can be active in State Machine at a given moment.
I've read that such State Machines are Nondeterministic finite automaton
, skimmed through wiki page, but that looks too theoretical for me.
Here is an example state machine:
s8
can be activated only when it received t7
and t8
, that means it should "wait".
The questions:
1. Is there something like "wait"
in state machines?
2. Maybe, this is not NFA, but two state machines? Should I care how to name this kind of semantic model at all?
3. Is it OK to s8
be implemented with some background thread, which accepts notifications from s4
and s7
, and is activated only when both of them sent notifications (this means that the unit test fail when timeout is reached, and then that timeout should be mentioned somewhere in a model) ?
Upvotes: 0
Views: 99
Reputation: 1990
Take a look at orthogonal regions in a hierarchical state machine, this should do what you are looking for.
Create a new state with two child regions: the first region containing s1, s2, s3, s4 and a new final state (the target of t8); the second region containing s5, s6, s7 and a new final state (the target of t7). Then add a new transition from the new state to s8.
The new transition should only be traversed when both regions are in a final state.
Upvotes: 1