4.5. Receivers

The question is what one can do with asynchronous channels. We have mentioned that these objects were designed with copy tasks in mind that transfer data from file descriptors into data objects. Of course, the asynchronous channels play the role of these data objects. In addition to these, we need an engine that actually performs this kind of data transfer: The receiver engine.

The receiver class has this signature:

   class receiver : src:Unix.file_descr ->
		    dst:#async_out_channel ->
		    ?close_src:bool ->
		    ?close_dst:bool ->
		    Unixqueue.event_system ->
		      [unit] engine
Obviously, src is the descriptor to get the data from, and dst is the asynchronous channel to write the data into. After the receiver has been created, it copies the data stream from src to dst until EOF is found.

The receiver is an engine, and this means that it reports its state to the outer world. When the copy task has been completed, it transitions into the state `Done().

In the next section we present a real example that also uses the receiver class.