ocaml-containers/dev/containers-thread/CCPool/Make/Fut/index.html
2021-08-02 17:37:24 +00:00

2 lines
No EOL
20 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>Fut (containers-thread.CCPool.Make.Fut)</title><link rel="stylesheet" href="../../../../odoc.css"/><meta charset="utf-8"/><meta name="generator" content="odoc 1.5.3"/><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-thread</a> &#x00BB; <a href="../../index.html">CCPool</a> &#x00BB; <a href="../index.html">Make</a> &#x00BB; Fut</nav><h1>Module <code>Make.Fut</code></h1><h5 id="futures"><a href="#futures" class="anchor"></a>Futures</h5><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><nav class="toc"><ul><li><a href="#constructors">Constructors</a></li><li><a href="#basics">Basics</a></li><li><a href="#combinators">Combinators</a></li></ul></nav></header><dl><dt class="spec type" id="type-t"><a href="#type-t" class="anchor"></a><code><span class="keyword">type</span> <span>'a t</span></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> <span>'a future</span></code><code> = <span><span class="type-var">'a</span> <a href="index.html#type-t">t</a></span></code></dt></dl><section><header><h3 id="constructors"><a href="#constructors" class="anchor"></a>Constructors</h3></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>&#45;&gt;</span> <span><span class="type-var">'a</span> <a href="index.html#type-t">t</a></span></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>&#45;&gt;</span> <span><span class="type-var">'a</span> <a href="index.html#type-t">t</a></span></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 : <span>(unit <span>&#45;&gt;</span> <span class="type-var">'a</span>)</span> <span>&#45;&gt;</span> <span><span class="type-var">'a</span> <a href="index.html#type-t">t</a></span></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>(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span>)</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> <span><span class="type-var">'b</span> <a href="index.html#type-t">t</a></span></code></dt><dt class="spec value" id="val-make2"><a href="#val-make2" class="anchor"></a><code><span class="keyword">val</span> make2 : <span>(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span> <span>&#45;&gt;</span> <span class="type-var">'c</span>)</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span> <span>&#45;&gt;</span> <span><span class="type-var">'c</span> <a href="index.html#type-t">t</a></span></code></dt></dl></section><section><header><h3 id="basics"><a href="#basics" class="anchor"></a>Basics</h3></header><dl><dt class="spec value" id="val-get"><a href="#val-get" class="anchor"></a><code><span class="keyword">val</span> get : <span><span class="type-var">'a</span> <a href="index.html#type-t">t</a></span> <span>&#45;&gt;</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><span class="type-var">'a</span> <a href="index.html#type-t">t</a></span> <span>&#45;&gt;</span> <span><span class="type-var">'a</span> <a href="../../index.html#type-state">state</a></span></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><span class="type-var">'a</span> <a href="index.html#type-t">t</a></span> <span>&#45;&gt;</span> bool</code></dt><dd><p>Is the future evaluated (success/failure)?</p></dd></dl></section><section><header><h3 id="combinators"><a href="#combinators" class="anchor"></a>Combinators</h3></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><span class="type-var">'a</span> <a href="index.html#type-t">t</a></span> <span>&#45;&gt;</span> <span>(<span class="type-var">'a</span> <span>&#45;&gt;</span> unit)</span> <span>&#45;&gt;</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><span class="type-var">_</span> <a href="index.html#type-t">t</a></span> <span>&#45;&gt;</span> <span>(exn <span>&#45;&gt;</span> unit)</span> <span>&#45;&gt;</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><span class="type-var">'a</span> <a href="index.html#type-t">t</a></span> <span>&#45;&gt;</span> <span>(<span><span class="type-var">'a</span> <a href="../../index.html#type-state">state</a></span> <span>&#45;&gt;</span> unit)</span> <span>&#45;&gt;</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>(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span><span class="type-var">'b</span> <a href="index.html#type-t">t</a></span>)</span> <span>&#45;&gt;</span> <span><span class="type-var">'a</span> <a href="index.html#type-t">t</a></span> <span>&#45;&gt;</span> <span><span class="type-var">'b</span> <a href="index.html#type-t">t</a></span></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><span class="type-var">'a</span> <a href="index.html#type-t">t</a></span> <span>&#45;&gt;</span> <span>(unit <span>&#45;&gt;</span> <span><span class="type-var">'b</span> <a href="index.html#type-t">t</a></span>)</span> <span>&#45;&gt;</span> <span><span class="type-var">'b</span> <a href="index.html#type-t">t</a></span></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><span><span class="type-var">'a</span> <a href="index.html#type-t">t</a></span> array</span> <span>&#45;&gt;</span> <span><span><span class="type-var">'a</span> array</span> <a href="index.html#type-t">t</a></span></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>(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span><span class="type-var">'b</span> <a href="index.html#type-t">t</a></span>)</span> <span>&#45;&gt;</span> <span><span class="type-var">'a</span> array</span> <span>&#45;&gt;</span> <span><span><span class="type-var">'b</span> array</span> <a href="index.html#type-t">t</a></span></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><span><span class="type-var">'a</span> <a href="index.html#type-t">t</a></span> list</span> <span>&#45;&gt;</span> <span><span><span class="type-var">'a</span> list</span> <a href="index.html#type-t">t</a></span></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>(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span><span class="type-var">'b</span> <a href="index.html#type-t">t</a></span>)</span> <span>&#45;&gt;</span> <span><span class="type-var">'a</span> list</span> <span>&#45;&gt;</span> <span><span><span class="type-var">'b</span> list</span> <a href="index.html#type-t">t</a></span></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><span><span class="type-var">'a</span> <a href="index.html#type-t">t</a></span> array</span> <span>&#45;&gt;</span> <span><span class="type-var">'a</span> <a href="index.html#type-t">t</a></span></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><span><span class="type-var">'a</span> <a href="index.html#type-t">t</a></span> list</span> <span>&#45;&gt;</span> <span><span class="type-var">'a</span> <a href="index.html#type-t">t</a></span></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>(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span>)</span> <span>&#45;&gt;</span> <span><span class="type-var">'a</span> <a href="index.html#type-t">t</a></span> <span>&#45;&gt;</span> <span><span class="type-var">'b</span> <a href="index.html#type-t">t</a></span></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>(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span>)</span> <span>&#45;&gt;</span> <span><span class="type-var">'a</span> <a href="index.html#type-t">t</a></span> <span>&#45;&gt;</span> <span><span class="type-var">'b</span> <a href="index.html#type-t">t</a></span></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-monoid_product"><a href="#val-monoid_product" class="anchor"></a><code><span class="keyword">val</span> monoid_product : <span>(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span> <span>&#45;&gt;</span> <span class="type-var">'c</span>)</span> <span>&#45;&gt;</span> <span><span class="type-var">'a</span> <a href="index.html#type-t">t</a></span> <span>&#45;&gt;</span> <span><span class="type-var">'b</span> <a href="index.html#type-t">t</a></span> <span>&#45;&gt;</span> <span><span class="type-var">'c</span> <a href="index.html#type-t">t</a></span></code></dt><dd><p>Cartesian product of the content of these futures.</p><dl><dt>since</dt><dd>2.8</dd></dl></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><span>(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span>)</span> <a href="index.html#type-t">t</a></span> <span>&#45;&gt;</span> <span><span class="type-var">'a</span> <a href="index.html#type-t">t</a></span> <span>&#45;&gt;</span> <span><span class="type-var">'b</span> <a href="index.html#type-t">t</a></span></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><span>(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span>)</span> <a href="index.html#type-t">t</a></span> <span>&#45;&gt;</span> <span><span class="type-var">'a</span> <a href="index.html#type-t">t</a></span> <span>&#45;&gt;</span> <span><span class="type-var">'b</span> <a href="index.html#type-t">t</a></span></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>&#45;&gt;</span> <span>unit <a href="index.html#type-t">t</a></span></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-(&gt;&gt;=)"><a href="#val-(&gt;&gt;=)" class="anchor"></a><code><span class="keyword">val</span> (&gt;&gt;=) : <span><span class="type-var">'a</span> <a href="index.html#type-t">t</a></span> <span>&#45;&gt;</span> <span>(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span><span class="type-var">'b</span> <a href="index.html#type-t">t</a></span>)</span> <span>&#45;&gt;</span> <span><span class="type-var">'b</span> <a href="index.html#type-t">t</a></span></code></dt><dt class="spec value" id="val-(&gt;&gt;)"><a href="#val-(&gt;&gt;)" class="anchor"></a><code><span class="keyword">val</span> (&gt;&gt;) : <span><span class="type-var">'a</span> <a href="index.html#type-t">t</a></span> <span>&#45;&gt;</span> <span>(unit <span>&#45;&gt;</span> <span><span class="type-var">'b</span> <a href="index.html#type-t">t</a></span>)</span> <span>&#45;&gt;</span> <span><span class="type-var">'b</span> <a href="index.html#type-t">t</a></span></code></dt><dt class="spec value" id="val-(&gt;|=)"><a href="#val-(&gt;|=)" class="anchor"></a><code><span class="keyword">val</span> (&gt;|=) : <span><span class="type-var">'a</span> <a href="index.html#type-t">t</a></span> <span>&#45;&gt;</span> <span>(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span>)</span> <span>&#45;&gt;</span> <span><span class="type-var">'b</span> <a href="index.html#type-t">t</a></span></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-(&lt;*&gt;)"><a href="#val-(&lt;*&gt;)" class="anchor"></a><code><span class="keyword">val</span> (&lt;*&gt;) : <span><span>(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span>)</span> <a href="index.html#type-t">t</a></span> <span>&#45;&gt;</span> <span><span class="type-var">'a</span> <a href="index.html#type-t">t</a></span> <span>&#45;&gt;</span> <span><span class="type-var">'b</span> <a href="index.html#type-t">t</a></span></code></dt><dd><p>Alias to <a href="index.html#val-app"><code>app</code></a>.</p></dd></dl><div><div class="spec include"><div class="doc"><p>Let operators on OCaml &gt;= 4.08.0, nothing otherwise</p><dl><dt>since</dt><dd>2.8</dd></dl><details open="open"><summary><span class="def"><code><span class="keyword">include</span> <a href="../../../../containers/CCShimsMkLet_/index.html#module-type-S">CCShimsMkLet_.S</a> <span class="keyword">with</span> <span class="keyword">type</span> <span>'a <a href="../../../../containers/CCShimsMkLet_/module-type-S/index.html#type-t_let">t_let</a></span> := <span><span class="type-var">'a</span> <a href="index.html#type-t">t</a></span></code></span></summary><dl><dt class="spec type" id="type-t_let"><a href="#type-t_let" class="anchor"></a><code><span class="keyword">type</span> <span>'a t_let</span></code></dt></dl><dl><dt class="spec value" id="val-let+"><a href="#val-let+" class="anchor"></a><code><span class="keyword">val</span> let+ : <span><span class="type-var">'a</span> <a href="index.html#type-t_let">t_let</a></span> <span>&#45;&gt;</span> <span>(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span>)</span> <span>&#45;&gt;</span> <span><span class="type-var">'b</span> <a href="index.html#type-t_let">t_let</a></span></code></dt><dt class="spec value" id="val-and+"><a href="#val-and+" class="anchor"></a><code><span class="keyword">val</span> and+ : <span><span class="type-var">'a</span> <a href="index.html#type-t_let">t_let</a></span> <span>&#45;&gt;</span> <span><span class="type-var">'b</span> <a href="index.html#type-t_let">t_let</a></span> <span>&#45;&gt;</span> <span><span>(<span class="type-var">'a</span> * <span class="type-var">'b</span>)</span> <a href="index.html#type-t_let">t_let</a></span></code></dt><dt class="spec value" id="val-let*"><a href="#val-let*" class="anchor"></a><code><span class="keyword">val</span> let* : <span><span class="type-var">'a</span> <a href="index.html#type-t_let">t_let</a></span> <span>&#45;&gt;</span> <span>(<span class="type-var">'a</span> <span>&#45;&gt;</span> <span><span class="type-var">'b</span> <a href="index.html#type-t_let">t_let</a></span>)</span> <span>&#45;&gt;</span> <span><span class="type-var">'b</span> <a href="index.html#type-t_let">t_let</a></span></code></dt><dt class="spec value" id="val-and*"><a href="#val-and*" class="anchor"></a><code><span class="keyword">val</span> and* : <span><span class="type-var">'a</span> <a href="index.html#type-t_let">t_let</a></span> <span>&#45;&gt;</span> <span><span class="type-var">'b</span> <a href="index.html#type-t_let">t_let</a></span> <span>&#45;&gt;</span> <span><span>(<span class="type-var">'a</span> * <span class="type-var">'b</span>)</span> <a href="index.html#type-t_let">t_let</a></span></code></dt></dl></details></div></div></div></section></div></body></html>