Previous sections illustrate how Orc can use the fork-join idiom to process a
fixed set of expressions or a list of values. Suppose that instead we wish to
process all the publications of an expression F, and once this processing is
complete, execute some expression G. For example, F publishes the contents
of a text file, one line at a time, and we wish to print each line to the
console using the site println
, then publish a signal after all lines
have been printed.
Sequential composition alone is not sufficient, because we have no way to
detect when all of the lines have been processed. A recursive fork-join
solution would require that the lines be stored in a traversable data structure
like a list, rather than streamed as publications from F. A better solution
uses the ;
combinator to detect when processing is complete:
F >x> println(x) >> stop ; signal
Since ;
only evaluates its right side if the left side does not publish,
we suppress the publications on the left side using stop
. Here, we
assume that we can detect when F halts. If, for example,
F is publishing the lines of the file as it receives them over a socket,
and the sending party never closes the socket, then F never halts and no
signal is published.