moonpool/picos_std/Picos_std_structured/Bundle/index.html
2025-09-26 19:08:06 +00:00

6 lines
8 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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>Bundle (picos_std.Picos_std_structured.Bundle)</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> &#x00BB; <a href="../../index.html">picos_std</a> &#x00BB; <a href="../index.html">Picos_std_structured</a> &#x00BB; Bundle</nav><header class="odoc-preamble"><h1>Module <code><span>Picos_std_structured.Bundle</span></code></h1><p>An explicit dynamic bundle of fibers guaranteed to be joined at the end.</p><p>Bundles allow you to conveniently structure or delimit concurrency into nested scopes. After a bundle returns or raises an exception, no fibers <a href="#val-fork" title="fork">forked</a> to the bundle remain.</p><p>An unhandled exception, or error, within any fiber of the bundle causes all of the fibers <a href="#val-fork" title="fork">forked</a> to the bundle to be canceled and the bundle to raise the error exception or <a href="../Control/index.html#exception-Errors" title="Control.Errors">error exceptions</a> raised by all of the fibers forked into the bundle.</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> t</span></code></div><div class="spec-doc"><p>Represents a bundle of fibers.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-join_after"><a href="#val-join_after" class="anchor"></a><code><span><span class="keyword">val</span> join_after :
<span><span class="optlabel">?callstack</span>:int <span class="arrow">&#45;&gt;</span></span>
<span><span class="optlabel">?on_return</span>:<span>[ `Terminate <span>| `Wait</span> ]</span> <span class="arrow">&#45;&gt;</span></span>
<span><span>(<span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'a</span>)</span> <span class="arrow">&#45;&gt;</span></span>
<span class="type-var">'a</span></span></code></div><div class="spec-doc"><p><code>join_after scope</code> calls <code>scope</code> with a <a href="#type-t" title="t">bundle</a>. A call of <code>join_after</code> returns or raises only after <code>scope</code> has returned or raised and all <a href="#val-fork" title="fork">forked</a> fibers have terminated. If <code>scope</code> raises an exception, <a href="#val-error"><code>error</code></a> will be called.</p><p>The optional <code>on_return</code> argument specifies what to do when the scope returns normally. It defaults to <code>`Wait</code>, which means to just wait for all the fibers to terminate on their own. When explicitly specified as <code>~on_return:`Terminate</code>, then <a href="#val-terminate" title="terminate"><code>terminate ?callstack</code></a> will be called on return. This can be convenient, for example, when dealing with <a href="https://en.wikipedia.org/wiki/Daemon_(computing)">daemon</a> fibers.</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">&#45;&gt;</span></span> <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p><code>terminate bundle</code> cancels all of the <a href="#val-fork" title="fork">forked</a> fibers using the <a href="../Control/index.html#exception-Terminate" title="Control.Terminate"><code>Terminate</code></a> exception. After <code>terminate</code> has been called, no new fibers can be forked to the bundle.</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><p> Calling <code>terminate</code> at the end of a bundle can be a convenient way to cancel any background fibers started by the bundle.</p><p> Calling <code>terminate</code> does not raise the <a href="../Control/index.html#exception-Terminate" title="Control.Terminate"><code>Terminate</code></a> exception, but blocking operations after <code>terminate</code> will raise the exception to propagate cancelation unless <a href="../Control/index.html#val-protect" title="Control.protect">propagation of cancelation is forbidden</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">&#45;&gt;</span></span> <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <span><span class="label">seconds</span>:float <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p><code>terminate_after ~seconds bundle</code> arranges to <a href="#val-terminate"><code>terminate</code></a> the bundle after the specified timeout in <code>seconds</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-error"><a href="#val-error" class="anchor"></a><code><span><span class="keyword">val</span> error : <span><span class="optlabel">?callstack</span>:int <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <span>exn <span class="arrow">&#45;&gt;</span></span> <span><a href="../../../ocaml/Stdlib/Printexc/index.html#type-raw_backtrace">Stdlib.Printexc.raw_backtrace</a> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p><code>error bundle exn bt</code> first calls <a href="#val-terminate"><code>terminate</code></a> and then adds the exception with backtrace to the list of exceptions to be raised, unless the exception is the <a href="../Control/index.html#exception-Terminate" title="Control.Terminate"><code>Terminate</code></a> exception, which is not considered to signal an error by itself.</p><p>The optional <code>callstack</code> argument is passed to <a href="#val-terminate"><code>terminate</code></a>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-fork_as_promise"><a href="#val-fork_as_promise" class="anchor"></a><code><span><span class="keyword">val</span> fork_as_promise : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <span><span>(<span>unit <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'a</span>)</span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <a href="../Promise/index.html#type-t">Promise.t</a></span></span></code></div><div class="spec-doc"><p><code>fork_as_promise bundle thunk</code> spawns a new fiber to the <code>bundle</code> that will run the given <code>thunk</code>. The result of the <code>thunk</code> will be written to the <a href="../Promise/index.html" title="Promise">promise</a>. If the <code>thunk</code> raises an exception, <a href="#val-error"><code>error</code></a> will be called with that exception.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-fork"><a href="#val-fork" class="anchor"></a><code><span><span class="keyword">val</span> fork : <span><a href="#type-t">t</a> <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> unit</span></code></div><div class="spec-doc"><p><code>fork bundle action</code> is equivalent to <a href="#val-fork_as_promise" title="fork_as_promise"><code>fork_as_promise bundle action |&gt; ignore</code></a>.</p></div></div></div></body></html>