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 channel('a);
The type of communication channels carrying values of type 'a
.
let new_channel: unit => channel('a);
Return a new channel.
type event(+'a);
The type of communication events returning a result of type 'a
.
let send: (channel('a), 'a) => event(unit);
send ch v
returns the event consisting in sending the value v
over the channel ch
. The result value of this event is ()
.
let receive: channel('a) => event('a);
receive ch
returns the event consisting in receiving a value
from the channel ch
. The result value of this event is the
value received.
let always: 'a => event('a);
always v
returns an event that is always ready for
synchronization. The result value of this event is v
.
let choose: list(event('a)) => event('a);
choose evl
returns the event that is the alternative of
all the events in the list evl
.
let wrap: (event('a), 'a => 'b) => event('b);
wrap ev fn
returns the event that performs the same communications
as ev
, then applies the post-processing function fn
on the return value.
let wrap_abort: (event('a), unit => unit) => event('a);
wrap_abort ev fn
returns the event that performs
the same communications as ev
, but if it is not selected
the function fn
is called after the synchronization.
let guard: (unit => event('a)) => event('a);
guard fn
returns the event that, when synchronized, computes
fn()
and behaves as the resulting event. This enables
computing events with side-effects at the time of the synchronization
operation.
let sync: event('a) => '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.
let select: list(event('a)) => 'a;
'Synchronize' on an alternative of events.
select evl
is shorthand for sync(choose evl)
.
let poll: event('a) => option('a);
Non-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 return
Some r
where r
is the result value of that communication.
Otherwise, return None
without blocking.