Asynchronous Task and Event Management

USAGE:

setReader(object, reader = standardReader, onQuit = NULL, con = as(object, 
        "connection"))
setMonitor(timeout, action, onQuit = NULL)

ARGUMENTS:

con
an input connection, such as a file or pipe. It is irrelevant whether the connection is open or not. In either case, it will be closed on quit or end-of-file.
reader
the reader function. This should be a function of one argument, the connection. In principle, the reader function can do anything, but to be useful it will normally read something from the connection and take some action with the result. The default reader function is evalParse. As its name suggests, this function parses one S expression from the connection and evaluates the result. This is similar to what happens with user expressions on standard input, except that there is no automatic printing. If you want an additional reader that behaves exactly as the standard S evaluation of tasks (including automatically showing the result of the evaluation, supply standardReader as the reader argument.
onQuit
the quit action. When a quit expression is returned by the reader function or (more typically) when end-of-file is reached on the connection, the connection is closed and the quit action, if any, is evaluated. If no quit action is supplied, a message is printed, reporting that the connection has been closed.
timeout
how long to wait (in seconds) before invoking the monitor's action.
action
the action to take when the timer runs down on a monitor. This should be a function with no arguments. Note that a monitor is not automatically reset: if you want the action to be called again, the last step in the action function should be to call resetMonitor() with an optional argument of the new timeout (by default the value given to setMonitor() is used).

Events:

These functions modify S event management. The standard S user interface runs an unending loop looking for outstanding events. An event is signalled if there is input waiting on one of the designated readers or if one of the monitors has timed out. When the S process starts up, a reader is established on standard input. Other readers or monitors may be established. Once a reader or monitor is established, the system looks for corresponding events.

Subevents:

Monitor events can also be checked within the evaluation of an expression; the actions triggered this way are subevents within the current task. Actions for subevents should be simple, if they are to be re-run with a small timeout value; otherwise, they threaten to eat up much the computing time. To turn sub-event monitoring on and off, use setSubEvent().

DETAILS:

These functions do not work on GUI versions of S-PLUS, and are not recommended for general use.

SEE ALSO:

, , , .

EXAMPLES:

## arrange to run a number of S test files through the do.test 
## function, each file as a separate task 
## The function is defined inline in the setReader() call 
setReader(textConnection(filenames), 
  function(con) do.test(pread(con, n=1)))