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.

Action : X .... move_to WAITING_FOR_SOMETHING ... State : WAITING_FOR_SOMETHING when(condition) move_to S ... when(condition) do Y Action: Y ...

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:

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.


WAIT_FOR Example
fig.1 - Example of WAIT_FOR usage. Notice the presence of the extra state WAITING_DEVICES_ON and action CONTINUE_START in the case when WAIT_FOR is not used.