Module Event
First-class synchronous communication.
This module implements synchronous inter-thread communications over channels. As in John Reppy's Concurrent ML system, the communication events are first-class values: they can be built and combined independently before being offered for communication.
val new_channel : unit -> 'a channelReturn a new channel.
val send : 'a channel -> 'a -> unit eventsend ch vreturns the event consisting in sending the valuevover the channelch. The result value of this event is().
val receive : 'a channel -> 'a eventreceive chreturns the event consisting in receiving a value from the channelch. The result value of this event is the value received.
val always : 'a -> 'a eventalways vreturns an event that is always ready for synchronization. The result value of this event isv.
val choose : 'a event list -> 'a eventchoose evlreturns the event that is the alternative of all the events in the listevl.
val wrap : 'a event -> ('a -> 'b) -> 'b eventwrap ev fnreturns the event that performs the same communications asev, then applies the post-processing functionfnon the return value.
val wrap_abort : 'a event -> (unit -> unit) -> 'a eventwrap_abort ev fnreturns the event that performs the same communications asev, but if it is not selected the functionfnis called after the synchronization.
val guard : (unit -> 'a event) -> 'a eventguard fnreturns the event that, when synchronized, computesfn()and behaves as the resulting event. This allows events with side-effects to be computed at the time of the synchronization operation.
val sync : 'a event -> 'a``Synchronize'' on an event: offer all the communication possibilities specified in the event to the outside world, and block until one of the communications succeed. The result value of that communication is returned.
val select : 'a event list -> 'a``Synchronize'' on an alternative of events.
select evlis shorthand forsync(choose evl).
val poll : 'a event -> 'a optionNon-blocking version of
Event.sync: offer all the communication possibilities specified in the event to the outside world, and if one can take place immediately, perform it and returnSome rwhereris the result value of that communication. Otherwise, returnNonewithout blocking.