Home Online Manual
Top
Back: waitall
Forward: wedge
FastBack: Functions and system variables
FastForward: Control structures
Up: Functions
Top: Singular Manual
Contents: Table of Contents
Index: Index
About: About this document

5.1.165 waitfirst

Syntax:
waitfirst ( list_expression )
waitfirst ( list_expression , int_expression )
Type:
int
Purpose:
Expects a list of open links (of mode ssi:fork, ssi:tcp) and waits until the first of them is finished, i.e., is ready to be read.
In the first case, the command waits until the first link is finished (or all of them crashed, see below) and may therefore run forever.
In the second case, a timeout in milliseconds can be provided, forcing the command to terminate after the specified time. If the given timeout is 0, the command checks whether one of the links is finished or not, but does not wait for any link (polling).
Return values are:
-1: The read state of all links is "eof", see link, status. This might happen if all the links crashed.
0: timeout (or polling): None of the links is ready.
i>1: At least the link whose list index is i is ready.
Example:
 
  link l1 = "ssi:fork"; open(l1);
  link l2 = "ssi:fork"; open(l2);
  link l3 = "ssi:fork"; open(l3);
  list l = list(l1,l2,l3);
  write(l1, quote(system("sh", "sleep 15")));
  write(l2, quote(system("sh", "sleep 13")));
  write(l3, quote(system("sh", "sleep 11")));
  waitfirst(l, 5000); // terminates after 5sec with result 0
==> 0
  waitfirst(l);       // terminates after 6 more sec with result 3
==> 3
  close(l1);
  close(l2);
  close(l3);
See waitall.