mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-06 03:05:30 -05:00
2 lines
7.6 KiB
HTML
2 lines
7.6 KiB
HTML
<!DOCTYPE html>
|
||
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Promise (picos_std.Picos_std_structured.Promise)</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_structured</a> » Promise</nav><header class="odoc-preamble"><h1>Module <code><span>Picos_std_structured.Promise</span></code></h1><p>A cancelable promise.</p><p>ℹ️ In addition to using a promise to concurrently compute and return a value, a cancelable promise can also represent a concurrent fiber that will continue until it is explicitly <a href="#val-try_terminate" title="try_terminate">canceled</a>.</p><p>⚠️ <a href="#val-try_terminate" title="try_terminate">Canceling</a> a promise does not immediately terminate the fiber or wait for the fiber working to complete the promise to terminate. Constructs like <a href="../Bundle/index.html#val-join_after"><code>Bundle.join_after</code></a> and <a href="../Flock/index.html#val-join_after"><code>Flock.join_after</code></a> only guarantee that all fibers forked within their scope have terminated before they return or raise. The reason for this design choice in this library is that synchronization is expensive and delaying synchronization to the join operation is typically sufficient and amortizes the cost.</p></header><div class="odoc-content"><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 promise to produce a value of type <code>'a</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-of_value"><a href="#val-of_value" class="anchor"></a><code><span><span class="keyword">val</span> of_value : <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>of_value value</code> returns a constant completed promise that returns the given <code>value</code>.</p><p>ℹ️ Promises can also be created in the scope of a <a href="../Bundle/index.html#val-fork_as_promise" title="Bundle.fork_as_promise"><code>Bundle</code></a> or a <a href="../Flock/index.html#val-fork_as_promise" title="Flock.fork_as_promise"><code>Flock</code></a>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-await"><a href="#val-await" class="anchor"></a><code><span><span class="keyword">val</span> await : <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>await promise</code> awaits until the promise has completed and either returns the <code>value</code> that the evaluation of the promise returned, raises the exception that the evaluation of the promise raised, or raises the <a href="../Control/index.html#exception-Terminate" title="Control.Terminate"><code>Terminate</code></a> exception in case the promise has been canceled.</p><p>⚠️ The fiber corresponding to a <a href="#val-try_terminate" title="try_terminate">canceled</a> promise is not guaranteed to have terminated at the point <code>await</code> raises.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-completed"><a href="#val-completed" class="anchor"></a><code><span><span class="keyword">val</span> completed : <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">'a</span> <a href="../../Picos_std_event/Event/index.html#type-t">Picos_std_event.Event.t</a></span></span></code></div><div class="spec-doc"><p><code>completed promise</code> returns an <a href="../../Picos_std_event/Event/index.html" title="Picos_std_event.Event">event</a> that can be committed to once the promise has completed.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-is_running"><a href="#val-is_running" class="anchor"></a><code><span><span class="keyword">val</span> is_running : <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_running promise</code> determines whether the completion of the promise is still pending.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-try_terminate"><a href="#val-try_terminate" class="anchor"></a><code><span><span class="keyword">val</span> try_terminate : <span><span class="optlabel">?callstack</span>:int <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> bool</span></code></div><div class="spec-doc"><p><code>try_terminate promise</code> tries to terminate the promise by canceling it with the <a href="../Control/index.html#exception-Terminate" title="Control.Terminate"><code>Terminate</code></a> exception and returns <code>true</code> in case of success and <code>false</code> in case the promise had already completed, i.e. either returned, raised, or canceled.</p><p>The optional <code>callstack</code> argument specifies the number of callstack entries to capture with the <a href="../Control/index.html#exception-Terminate" title="Control.Terminate"><code>Terminate</code></a> exception. The default is <code>0</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-terminate"><a href="#val-terminate" class="anchor"></a><code><span><span class="keyword">val</span> terminate : <span><span class="optlabel">?callstack</span>:int <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> unit</span></code></div><div class="spec-doc"><p><code>terminate promise</code> is equivalent to <a href="#val-try_terminate" title="try_terminate"><code>try_terminate promise |> ignore</code></a>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-terminate_after"><a href="#val-terminate_after" class="anchor"></a><code><span><span class="keyword">val</span> terminate_after : <span><span class="optlabel">?callstack</span>:int <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="label">seconds</span>:float <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p><code>terminate_after ~seconds promise</code> arranges to terminate the <code>promise</code> by canceling it with the <a href="../Control/index.html#exception-Terminate" title="Control.Terminate"><code>Terminate</code></a> exception after the specified timeout in <code>seconds</code>.</p><p>The optional <code>callstack</code> argument specifies the number of callstack entries to capture with the <a href="../Control/index.html#exception-Terminate" title="Control.Terminate"><code>Terminate</code></a> exception. The default is <code>0</code>.</p></div></div></div></body></html>
|