mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-07 11:45:31 -05:00
2 lines
No EOL
15 KiB
HTML
2 lines
No EOL
15 KiB
HTML
<!DOCTYPE html>
|
||
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Fut (containers.CCPool.Make.Fut)</title><link rel="stylesheet" href="../../../../odoc.css"/><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body><div class="content"><header><nav><a href="../index.html">Up</a> – <a href="../../../index.html">containers</a> » <a href="../../index.html">CCPool</a> » <a href="../index.html">Make</a> » Fut</nav><h1>Module <code>Make.Fut</code></h1><h4 id="futures"><a href="#futures" class="anchor"></a>Futures</h4><p>The futures are registration points for callbacks, storing a <a href="index.html#val-state"><code>state</code></a>, that are executed in the pool using <a href="../index.html#val-run"><code>run</code></a>.</p></header><dl><dt class="spec type" id="type-t"><a href="#type-t" class="anchor"></a><code><span class="keyword">type </span>'a t</code></dt><dd><p>A future value of type <code>'a</code></p></dd></dl><dl><dt class="spec type" id="type-future"><a href="#type-future" class="anchor"></a><code><span class="keyword">type </span>'a future</code><code><span class="keyword"> = </span><span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt></dl><section><header><h2 id="constructors"><a href="#constructors" class="anchor"></a>Constructors</h2></header><dl><dt class="spec value" id="val-return"><a href="#val-return" class="anchor"></a><code><span class="keyword">val </span>return : <span class="type-var">'a</span> <span>-></span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Future that is already computed.</p></dd></dl><dl><dt class="spec value" id="val-fail"><a href="#val-fail" class="anchor"></a><code><span class="keyword">val </span>fail : exn <span>-></span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Future that fails immediately.</p></dd></dl><dl><dt class="spec value" id="val-make"><a href="#val-make" class="anchor"></a><code><span class="keyword">val </span>make : (unit <span>-></span> <span class="type-var">'a</span>) <span>-></span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Create a future, representing a value that will be computed by the function. If the function raises, the future will fail.</p></dd></dl><dl><dt class="spec value" id="val-make1"><a href="#val-make1" class="anchor"></a><code><span class="keyword">val </span>make1 : (<span class="type-var">'a</span> <span>-></span> <span class="type-var">'b</span>) <span>-></span> <span class="type-var">'a</span> <span>-></span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a></code></dt><dt class="spec value" id="val-make2"><a href="#val-make2" class="anchor"></a><code><span class="keyword">val </span>make2 : (<span class="type-var">'a</span> <span>-></span> <span class="type-var">'b</span> <span>-></span> <span class="type-var">'c</span>) <span>-></span> <span class="type-var">'a</span> <span>-></span> <span class="type-var">'b</span> <span>-></span> <span class="type-var">'c</span> <a href="index.html#type-t">t</a></code></dt></dl></section><section><header><h2 id="basics"><a href="#basics" class="anchor"></a>Basics</h2></header><dl><dt class="spec value" id="val-get"><a href="#val-get" class="anchor"></a><code><span class="keyword">val </span>get : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>-></span> <span class="type-var">'a</span></code></dt><dd><p>Blocking get: wait for the future to be evaluated, and get the value, or the exception that failed the future is returned. Raise e if the future failed with e.</p></dd></dl><dl><dt class="spec value" id="val-state"><a href="#val-state" class="anchor"></a><code><span class="keyword">val </span>state : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>-></span> <span class="type-var">'a</span> <a href="../../index.html#type-state">state</a></code></dt><dd><p>State of the future.</p></dd></dl><dl><dt class="spec value" id="val-is_done"><a href="#val-is_done" class="anchor"></a><code><span class="keyword">val </span>is_done : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>-></span> bool</code></dt><dd><p>Is the future evaluated (success/failure)?</p></dd></dl></section><section><header><h2 id="combinators"><a href="#combinators" class="anchor"></a>Combinators</h2></header><dl><dt class="spec value" id="val-on_success"><a href="#val-on_success" class="anchor"></a><code><span class="keyword">val </span>on_success : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>-></span> (<span class="type-var">'a</span> <span>-></span> unit) <span>-></span> unit</code></dt><dd><p>Attach a handler to be called upon success. The handler should not call functions on the future. Might be evaluated now if the future is already done.</p></dd></dl><dl><dt class="spec value" id="val-on_failure"><a href="#val-on_failure" class="anchor"></a><code><span class="keyword">val </span>on_failure : <span class="type-var">_</span> <a href="index.html#type-t">t</a> <span>-></span> (exn <span>-></span> unit) <span>-></span> unit</code></dt><dd><p>Attach a handler to be called upon failure. The handler should not call any function on the future. Might be evaluated now if the future is already done.</p></dd></dl><dl><dt class="spec value" id="val-on_finish"><a href="#val-on_finish" class="anchor"></a><code><span class="keyword">val </span>on_finish : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>-></span> (<span class="type-var">'a</span> <a href="../../index.html#type-state">state</a> <span>-></span> unit) <span>-></span> unit</code></dt><dd><p>Attach a handler to be called when the future is evaluated. The handler should not call functions on the future. Might be evaluated now if the future is already done.</p></dd></dl><dl><dt class="spec value" id="val-flat_map"><a href="#val-flat_map" class="anchor"></a><code><span class="keyword">val </span>flat_map : (<span class="type-var">'a</span> <span>-></span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a>) <span>-></span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>-></span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Monadic combination of futures.</p></dd></dl><dl><dt class="spec value" id="val-and_then"><a href="#val-and_then" class="anchor"></a><code><span class="keyword">val </span>and_then : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>-></span> (unit <span>-></span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a>) <span>-></span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Wait for the first future to succeed, then launch the second.</p></dd></dl><dl><dt class="spec value" id="val-sequence_a"><a href="#val-sequence_a" class="anchor"></a><code><span class="keyword">val </span>sequence_a : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> array <span>-></span> <span class="type-var">'a</span> array <a href="index.html#type-t">t</a></code></dt><dd><p>Future that waits for all previous futures to terminate. If any future in the array fails, <code>sequence_a l</code> fails too.</p></dd></dl><dl><dt class="spec value" id="val-map_a"><a href="#val-map_a" class="anchor"></a><code><span class="keyword">val </span>map_a : (<span class="type-var">'a</span> <span>-></span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a>) <span>-></span> <span class="type-var">'a</span> array <span>-></span> <span class="type-var">'b</span> array <a href="index.html#type-t">t</a></code></dt><dd><p><code>map_a f a</code> maps <code>f</code> on every element of <code>a</code>, and will return the array of every result if all calls succeed, or an error otherwise.</p></dd></dl><dl><dt class="spec value" id="val-sequence_l"><a href="#val-sequence_l" class="anchor"></a><code><span class="keyword">val </span>sequence_l : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> list <span>-></span> <span class="type-var">'a</span> list <a href="index.html#type-t">t</a></code></dt><dd><p>Future that waits for all previous futures to terminate. If any future in the list fails, <code>sequence_l l</code> fails too.</p></dd></dl><dl><dt class="spec value" id="val-map_l"><a href="#val-map_l" class="anchor"></a><code><span class="keyword">val </span>map_l : (<span class="type-var">'a</span> <span>-></span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a>) <span>-></span> <span class="type-var">'a</span> list <span>-></span> <span class="type-var">'b</span> list <a href="index.html#type-t">t</a></code></dt><dd><p><code>map_l f l</code> maps <code>f</code> on every element of <code>l</code>, and will return the list of every result if all calls succeed, or an error otherwise.</p></dd></dl><dl><dt class="spec value" id="val-choose_a"><a href="#val-choose_a" class="anchor"></a><code><span class="keyword">val </span>choose_a : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> array <span>-></span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Choose among those futures (the first to terminate). Behaves like the first future that terminates, by failing if the future fails.</p></dd></dl><dl><dt class="spec value" id="val-choose_l"><a href="#val-choose_l" class="anchor"></a><code><span class="keyword">val </span>choose_l : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> list <span>-></span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Choose among those futures (the first to terminate). Behaves like the first future that terminates, by failing if the future fails.</p></dd></dl><dl><dt class="spec value" id="val-map"><a href="#val-map" class="anchor"></a><code><span class="keyword">val </span>map : (<span class="type-var">'a</span> <span>-></span> <span class="type-var">'b</span>) <span>-></span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>-></span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Map the value inside the future. The function doesn't run in its own task; if it can take time, use <a href="index.html#val-flat_map"><code>flat_map</code></a> or <a href="index.html#val-map_async"><code>map_async</code></a>.</p></dd></dl><dl><dt class="spec value" id="val-map_async"><a href="#val-map_async" class="anchor"></a><code><span class="keyword">val </span>map_async : (<span class="type-var">'a</span> <span>-></span> <span class="type-var">'b</span>) <span>-></span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>-></span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Map the value inside the future, to be computed in a separated job.</p></dd></dl><dl><dt class="spec value" id="val-app"><a href="#val-app" class="anchor"></a><code><span class="keyword">val </span>app : (<span class="type-var">'a</span> <span>-></span> <span class="type-var">'b</span>) <a href="index.html#type-t">t</a> <span>-></span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>-></span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>app f x</code> applies the result of <code>f</code> to the result of <code>x</code>.</p></dd></dl><dl><dt class="spec value" id="val-app_async"><a href="#val-app_async" class="anchor"></a><code><span class="keyword">val </span>app_async : (<span class="type-var">'a</span> <span>-></span> <span class="type-var">'b</span>) <a href="index.html#type-t">t</a> <span>-></span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>-></span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>app_async f x</code> applies the result of <code>f</code> to the result of <code>x</code>, in a separated job scheduled in the pool.</p></dd></dl><dl><dt class="spec value" id="val-sleep"><a href="#val-sleep" class="anchor"></a><code><span class="keyword">val </span>sleep : float <span>-></span> unit <a href="index.html#type-t">t</a></code></dt><dd><p>Future that returns with success in the given amount of seconds. Blocks the thread! If you need to wait on many events, consider using <a href="../../../CCTimer/index.html"><code>CCTimer</code></a>.</p></dd></dl><div class="spec module" id="module-Infix"><a href="#module-Infix" class="anchor"></a><code><span class="keyword">module </span><a href="Infix/index.html">Infix</a> : <span class="keyword">sig</span> ... <span class="keyword">end</span></code></div><dl><dt class="spec value" id="val-(>>=)"><a href="#val-(>>=)" class="anchor"></a><code><span class="keyword">val </span>(>>=) : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>-></span> (<span class="type-var">'a</span> <span>-></span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a>) <span>-></span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a></code></dt><dt class="spec value" id="val-(>>)"><a href="#val-(>>)" class="anchor"></a><code><span class="keyword">val </span>(>>) : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>-></span> (unit <span>-></span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a>) <span>-></span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a></code></dt><dt class="spec value" id="val-(>|=)"><a href="#val-(>|=)" class="anchor"></a><code><span class="keyword">val </span>(>|=) : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>-></span> (<span class="type-var">'a</span> <span>-></span> <span class="type-var">'b</span>) <span>-></span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Alias to <a href="index.html#val-map"><code>map</code></a>.</p></dd></dl><dl><dt class="spec value" id="val-(<*>)"><a href="#val-(<*>)" class="anchor"></a><code><span class="keyword">val </span>(<*>) : (<span class="type-var">'a</span> <span>-></span> <span class="type-var">'b</span>) <a href="index.html#type-t">t</a> <span>-></span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>-></span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Alias to <a href="index.html#val-app"><code>app</code></a>.</p></dd></dl></section></div></body></html> |