WAIT_FOR instruction
Sometimes it is necessary to wait for a specific situation to arise before continuing. This has been typically handled by creating an extra state, moving into it and then waiting there for that situation to happen. See example below.
This unfortunately has the consequence of proliferation of extra states and actions and not only in the current object but also in objects that take the current object state into account. WAIT_FOR instruction simplifies this situation.
Syntax:
WAIT_FOR
when (condition1) response1
...
when (conditionn) responsen
END_WAIT_FOR
where responsei is the response to conditioni being TRUE and is one of the following:
- move_to state-name
Will interrupt the execution of WAIT_FOR and put the current object into state state-name - continue
Will interrupt the execution of WAIT_FOR and the execution will continue with the instruction following END_WAIT_FOR
At the start of the execution of WAIT_FOR construct, the when conditions are executed one by one in the given order. The first one giving TRUE answer will cause the execution of its response and consequently terminates the WAIT_FOR construct. If none of the conditions is TRUE, then WAIT_FOR, the current action and the current object are suspended.
State Manager handling
When during the execution of an action WAIT_FOR construct is reached and none of the when conditions is TRUE, the execution of the construct and thus the current action is suspended in the similar (but not identical) way as IF instruction.
Later, when SCHEDULER detects the situation in which one of the conditions of the suspended whens might give the positive answer, it asks the suspended object to evaluate the conditions of the suspended whens and if one of them gives the positive answer, it resumes the execution of the suspended object, the corresponding response is executed end the WAIT_FOR is terminated.
