moonpool/dev/ocaml/Event/index.html
2023-08-28 17:11:38 +00:00

2 lines
No EOL
8.3 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Event (ocaml.Event)</title><link rel="stylesheet" href="../../_odoc-theme/odoc.css"/><meta charset="utf-8"/><meta name="generator" content="odoc 2.2.1"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body class="odoc"><nav class="odoc-nav"><a href="../index.html">Up</a> <a href="../index.html">ocaml</a> &#x00BB; Event</nav><header class="odoc-preamble"><h1>Module <code><span>Event</span></code></h1><p>First-class synchronous communication.</p><p>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.</p></header><div class="odoc-content"><div class="odoc-spec"><div class="spec type anchored" id="type-channel"><a href="#type-channel" class="anchor"></a><code><span><span class="keyword">type</span> <span>'a channel</span></span></code></div><div class="spec-doc"><p>The type of communication channels carrying values of type <code>'a</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-new_channel"><a href="#val-new_channel" class="anchor"></a><code><span><span class="keyword">val</span> new_channel : <span>unit <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <a href="#type-channel">channel</a></span></span></code></div><div class="spec-doc"><p>Return a new channel.</p></div></div><div class="odoc-spec"><div class="spec type anchored" id="type-event"><a href="#type-event" class="anchor"></a><code><span><span class="keyword">type</span> <span>+'a event</span></span></code></div><div class="spec-doc"><p>The type of communication events returning a result of type <code>'a</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-send"><a href="#val-send" class="anchor"></a><code><span><span class="keyword">val</span> send : <span><span><span class="type-var">'a</span> <a href="#type-channel">channel</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> <span>unit <a href="#type-event">event</a></span></span></code></div><div class="spec-doc"><p><code>send ch v</code> returns the event consisting in sending the value <code>v</code> over the channel <code>ch</code>. The result value of this event is <code>()</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-receive"><a href="#val-receive" class="anchor"></a><code><span><span class="keyword">val</span> receive : <span><span><span class="type-var">'a</span> <a href="#type-channel">channel</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <a href="#type-event">event</a></span></span></code></div><div class="spec-doc"><p><code>receive ch</code> returns the event consisting in receiving a value from the channel <code>ch</code>. The result value of this event is the value received.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-always"><a href="#val-always" class="anchor"></a><code><span><span class="keyword">val</span> always : <span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <a href="#type-event">event</a></span></span></code></div><div class="spec-doc"><p><code>always v</code> returns an event that is always ready for synchronization. The result value of this event is <code>v</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-choose"><a href="#val-choose" class="anchor"></a><code><span><span class="keyword">val</span> choose : <span><span><span><span class="type-var">'a</span> <a href="#type-event">event</a></span> list</span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <a href="#type-event">event</a></span></span></code></div><div class="spec-doc"><p><code>choose evl</code> returns the event that is the alternative of all the events in the list <code>evl</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-wrap"><a href="#val-wrap" class="anchor"></a><code><span><span class="keyword">val</span> wrap : <span><span><span class="type-var">'a</span> <a href="#type-event">event</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span>(<span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'b</span>)</span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'b</span> <a href="#type-event">event</a></span></span></code></div><div class="spec-doc"><p><code>wrap ev fn</code> returns the event that performs the same communications as <code>ev</code>, then applies the post-processing function <code>fn</code> on the return value.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-wrap_abort"><a href="#val-wrap_abort" class="anchor"></a><code><span><span class="keyword">val</span> wrap_abort : <span><span><span class="type-var">'a</span> <a href="#type-event">event</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span>(<span>unit <span class="arrow">&#45;&gt;</span></span> unit)</span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <a href="#type-event">event</a></span></span></code></div><div class="spec-doc"><p><code>wrap_abort ev fn</code> returns the event that performs the same communications as <code>ev</code>, but if it is not selected the function <code>fn</code> is called after the synchronization.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-guard"><a href="#val-guard" class="anchor"></a><code><span><span class="keyword">val</span> guard : <span><span>(<span>unit <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <a href="#type-event">event</a></span>)</span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <a href="#type-event">event</a></span></span></code></div><div class="spec-doc"><p><code>guard fn</code> returns the event that, when synchronized, computes <code>fn()</code> and behaves as the resulting event. This enables computing events with side-effects at the time of the synchronization operation.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-sync"><a href="#val-sync" class="anchor"></a><code><span><span class="keyword">val</span> sync : <span><span><span class="type-var">'a</span> <a href="#type-event">event</a></span> <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'a</span></span></code></div><div class="spec-doc"><p>'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.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-select"><a href="#val-select" class="anchor"></a><code><span><span class="keyword">val</span> select : <span><span><span><span class="type-var">'a</span> <a href="#type-event">event</a></span> list</span> <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'a</span></span></code></div><div class="spec-doc"><p>'Synchronize' on an alternative of events. <code>select evl</code> is shorthand for <code>sync(choose evl)</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-poll"><a href="#val-poll" class="anchor"></a><code><span><span class="keyword">val</span> poll : <span><span><span class="type-var">'a</span> <a href="#type-event">event</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> option</span></span></code></div><div class="spec-doc"><p>Non-blocking version of <a href="#val-sync"><code>Event.sync</code></a>: offer all the communication possibilities specified in the event to the outside world, and if one can take place immediately, perform it and return <code>Some r</code> where <code>r</code> is the result value of that communication. Otherwise, return <code>None</code> without blocking.</p></div></div></div></body></html>