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.154 waitfirst

Syntax:
waitfirst ( list_expression ) waitfirst ( list_expression , int_expression )
Type:
int
Purpose:
Expects a list of open ssi links of mode fork or tcp and waits until the first of them is finished, i.e., is ready to be read.
In the first case, the command waits for the first link to finish (and may therefore run forever), and returns the list index of the terminated link.
In the second case, a timeout in milliseconds can be provided, forcing the command to terminate after the specified time (return value = 0), or - in case this happens earlier - when the first link is finished (return value = list index of terminated link).
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.

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
            User manual for Singular version 3-1-2, Oct 2010, generated by texi2html.