Event(3) OCaml library Event(3)

# [NAME](#NAME)

Event - First-class synchronous communication.

# [Module](#Module)

Module Event

# [Documentation](#Documentation)

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 -&gt; 'a channel**

Return a new channel.

*type* **+'a** *event*

The type of communication events returning a result of type **'a** .

*val send* : **'a channel -&gt; 'a -&gt; 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 -&gt; '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 -&gt; 'a event**

**always v** returns an event that is always ready for synchronization. The result value of this event is **v** .

*val choose* : **'a event list -&gt; 'a event**

**choose evl** returns the event that is the alternative of all the events in the list **evl** .

*val wrap* : **'a event -&gt; ('a -&gt; 'b) -&gt; '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 wrap\_abort* : **'a event -&gt; (unit -&gt; unit) -&gt; 'a event**

**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.

*val guard* : **(unit -&gt; 'a event) -&gt; 'a event**

**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.

*val sync* : **'a event -&gt; '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 -&gt; 'a**

'Synchronize' on an alternative of events. **select evl** is shorthand for **sync(choose evl)** .

*val poll* : **'a event -&gt; 'a option**

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.

2026-09-04 OCamldoc

---

Document: Event(3o) from ocaml 5.5.1-r0 (Chainguard OS)
Source: https://github.com/ocaml/ocaml
