mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-06 03:05:30 -05:00
5 lines
6.6 KiB
HTML
5 lines
6.6 KiB
HTML
<!DOCTYPE html>
|
||
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Lazy (picos_std.Picos_std_sync.Lazy)</title><meta charset="utf-8"/><link rel="stylesheet" href="../../../_odoc-theme/odoc.css"/><meta name="generator" content="odoc 3.1.0"/><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">Index</a> » <a href="../../index.html">picos_std</a> » <a href="../index.html">Picos_std_sync</a> » Lazy</nav><header class="odoc-preamble"><h1>Module <code><span>Picos_std_sync.Lazy</span></code></h1><p>A lazy suspension.</p><p>ℹ️ This intentionally mimics the interface of <a href="../../../ocaml/Stdlib/Lazy/index.html"><code>Stdlib.Lazy</code></a>. Unlike with the standard library suspensions an attempt to force a suspension from multiple fibers, possibly running on different domains, does not raise the <a href="#exception-Undefined"><code>Undefined</code></a> exception.</p></header><div class="odoc-content"><div class="odoc-spec"><div class="spec exception anchored" id="exception-Undefined"><a href="#exception-Undefined" class="anchor"></a><code><span><span class="keyword">exception</span> </span><span><span class="exception">Undefined</span></span></code></div><div class="spec-doc"><p>Synonym for <a href="../../../ocaml/Stdlib/Lazy/index.html#exception-Undefined"><code>Stdlib.Lazy.Undefined</code></a>.</p></div></div><div class="odoc-spec"><div class="spec type anchored" id="type-t"><a href="#type-t" class="anchor"></a><code><span><span class="keyword">type</span> <span>!'a t</span></span></code></div><div class="spec-doc"><p>Represents a deferred computation or suspension.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-from_fun"><a href="#val-from_fun" class="anchor"></a><code><span><span class="keyword">val</span> from_fun : <span><span>(<span>unit <span class="arrow">-></span></span> <span class="type-var">'a</span>)</span> <span class="arrow">-></span></span> <span><span class="type-var">'a</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p><code>from_fun thunk</code> returns a suspension.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-from_val"><a href="#val-from_val" class="anchor"></a><code><span><span class="keyword">val</span> from_val : <span><span class="type-var">'a</span> <span class="arrow">-></span></span> <span><span class="type-var">'a</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p><code>from_val value</code> returns an already forced suspension whose result is the given <code>value</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-is_val"><a href="#val-is_val" class="anchor"></a><code><span><span class="keyword">val</span> is_val : <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">-></span></span> bool</span></code></div><div class="spec-doc"><p><code>is_val susp</code> determines whether the suspension has already been forced and didn't raise an exception.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-force"><a href="#val-force" class="anchor"></a><code><span><span class="keyword">val</span> force : <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">-></span></span> <span class="type-var">'a</span></span></code></div><div class="spec-doc"><p><code>force susp</code> forces the suspension, i.e. computes <code>thunk ()</code> using the <code>thunk</code> passed to <a href="#val-from_fun"><code>from_fun</code></a>, stores the result of the computation to the suspension and reproduces its result. In case the suspension has already been forced the computation is skipped and stored result is reproduced.</p><p>ℹ️ This will check whether the current fiber has been canceled before starting the computation of <code>thunk ()</code>. This allows the suspension to be forced by another fiber. However, if the fiber is canceled and the cancelation exception is raised after the computation has been started, the suspension will then store the cancelation exception.</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <a href="#exception-Undefined"><code>Undefined</code></a> <p>in case the suspension is currently being forced by the <a href="../../../picos/Picos/Fiber/index.html#val-current" title="Picos.Fiber.current">current</a> fiber.</p></li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-force_val"><a href="#val-force_val" class="anchor"></a><code><span><span class="keyword">val</span> force_val : <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">-></span></span> <span class="type-var">'a</span></span></code></div><div class="spec-doc"><p><code>force_val</code> is a synonym for <a href="#val-force"><code>force</code></a>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-map"><a href="#val-map" class="anchor"></a><code><span><span class="keyword">val</span> map : <span><span>(<span><span class="type-var">'a</span> <span class="arrow">-></span></span> <span class="type-var">'b</span>)</span> <span class="arrow">-></span></span> <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">-></span></span> <span><span class="type-var">'b</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p><code>map fn susp</code> is equivalent to <a href="#val-from_fun" title="from_fun"><code>from_fun (fun () -> fn (force susp))</code></a>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-map_val"><a href="#val-map_val" class="anchor"></a><code><span><span class="keyword">val</span> map_val : <span><span>(<span><span class="type-var">'a</span> <span class="arrow">-></span></span> <span class="type-var">'b</span>)</span> <span class="arrow">-></span></span> <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">-></span></span> <span><span class="type-var">'b</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p><code>map_val fn susp</code> is equivalent to:</p><pre class="language-ocaml"><code> if is_val susp then
|
||
from_val (fn (force susp))
|
||
else
|
||
map fn susp</code></pre></div></div></div></body></html>
|