Module Ccell.Event


module Event: sig .. end
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.


type 'a channel 
The type of communication channels carrying values of type 'a.
val new_channel : unit -> 'a channel
Return a new channel.
type 'a event 
The type of communication events returning a result of type 'a.
val send : 'a channel -> 'a -> unit event
send ch v returns the event consisting in sending the value v over the channel ch. The result value of this event is ().
val receive : 'a channel -> 'a event
receive ch returns the event consisting in receiving a value from the channel ch. The result value of this event is the value received.
val always : 'a -> 'a event
always v returns an event that is always ready for ynchronization. The result value of this event is v.
val choose : 'a event list -> 'a event
choose evl returns the event that is the alternative of all the events in the list evl.
val wrap : 'a event -> ('a -> 'b) -> 'b event
wrap ev fn returns the event that performs the same communications as ev, then applies the post-processing function fn on the return value.
val guard : (unit -> 'a event) -> 'a event
guard fn returns the event that, when synchronized, computes fn() and behaves as the resulting event. This allows to compute events with side-effects at the time of the synchronization operation.
val join : 'a event event -> 'a event
join ee returns the event that returns a value when both outside and inside event are performed. Note this combinator is not transactional. That's means that the outer event will be performed independently whether inner event will be performed or not.
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 evl is shorthand for sync(choose evl).
val poll : 'a event -> 'a option
Non-blocking version of Ccell.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 return Some r where r is the result value of that communication. Otherwise, return None without blocking.
val never : 'a event
never an event value that is never enabled for synchronization.
val return : 'a -> 'a event
same as always
val bind : 'a event -> ('a -> 'b event) -> 'b event
bind ev fn returns the event that will be generated by fn
val (>>=) : 'a event -> ('a -> 'b event) -> 'b event
same as bind
val (>>) : 'a event -> 'b event -> 'b event
m >> k is same as bind m (fun _ -> k)
val fmap : ('a -> 'b) -> 'a event -> 'b event
fmap fn ev is same as wrap ev fn
val fmap2 : ('a -> 'b -> 'c) ->
'a event -> 'b event -> 'c event
fmap2 fn ev1 ev2 returns the event that
val app : ('a -> 'b) event -> 'a event -> 'b event
app fn ev is same as fmap2 (fun f v -> f v) fn ev
val mzero : 'a event
same as never
val mplus : 'a event -> 'a event -> 'a event
mplus ev1 ev2 is same as choose [ev1; ev2]
val receive_reserve : 'a channel -> 'a Ccell.Ivar.t
receive_reserve ch returns the ivar which will store the next received value on channel ch.
val filter : ('a -> bool) -> 'a event -> 'a event
filter fn ev returns filtered event that is only fn is true
val filter_map : ('a -> 'b option) -> 'a event -> 'b event
filter_map fn ev
val sequence : 'a event list -> 'a list event
sequence evl returns the event that contains all performed values of evl.
val future : ('a -> 'b) -> 'a -> 'b event
future fn x returns the event that will store the result of fn x. this function create a thread to compute fn x.
module Cell: sig .. end
thread safe reference cell.