9.7.4 Asynchronous Transfer of Control
An asynchronous
select_statement
provides asynchronous transfer of control upon completion of an entry
call or the expiration of a delay.
Syntax
Dynamic Semantics
For the execution
of an
asynchronous_select
whose
triggering_statement
is a
procedure_or_entry_call,
the
entry_name,
procedure_name,
or
procedure_prefix,
and actual parameters are evaluated as for a simple entry call (see
9.5.3)
or procedure call (see
6.4). If the call is
an entry call or a call on a procedure implemented by an entry, the entry
call is issued. If the entry call is queued (or requeued-with-abort),
then the
abortable_part
is executed. If the entry call is selected immediately, and never requeued-with-abort,
then the
abortable_part
is never started. If the call is on a procedure that is not implemented
by an entry, the call proceeds as described in
6.4,
followed by the
sequence_of_statements
of the
triggering_alternative;
the
abortable_part
is never started.
Examples
Example
of a main command loop for a command interpreter:
loop
select
Terminal.Wait_For_Interrupt;
Put_Line("Interrupted");
then abort
-- This will be abandoned upon terminal interrupt
Put_Line("-> ");
Get_Line(Command, Last);
Process_Command(Command(1..Last));
end select;
end loop;
Example of a time-limited
calculation:
select
delay 5.0;
Put_Line("Calculation does not converge");
then abort
-- This calculation should finish in 5.0 seconds;
-- if not, it is assumed to diverge.
Horribly_Complicated_Recursive_Function(X, Y);
end select;