moonpool/moonpool-lwt/Moonpool_lwt/index.html
2025-10-02 18:40:05 +00:00

2 lines
9.3 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>Moonpool_lwt (moonpool-lwt.Moonpool_lwt)</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">moonpool-lwt</a> &#x00BB; Moonpool_lwt</nav><header class="odoc-preamble"><h1>Module <code><span>Moonpool_lwt</span></code></h1><p>Lwt_engine-based event loop for Moonpool.</p><p>In what follows, we mean by &quot;lwt thread&quot; the thread running <a href="#val-lwt_main"><code>lwt_main</code></a> (which wraps <code>Lwt_main.run</code>; so, the thread where the Lwt event loop and all Lwt callbacks execute).</p><p><b>NOTE</b>: this is experimental and might change in future versions.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 0.6</li></ul><p>The API has entirely changed since 0.9 , see https://github.com/c-cube/moonpool/pull/37</p></header><div class="odoc-tocs"><nav class="odoc-toc odoc-local-toc"><ul><li><a href="#basic-conversions">Basic conversions</a></li><li><a href="#helpers-on-the-moonpool-side">Helpers on the moonpool side</a></li><li><a href="#wrappers-around-lwt_main">Wrappers around Lwt_main</a></li></ul></nav></div><div class="odoc-content"><div class="odoc-spec"><div class="spec module anchored" id="module-Fut"><a href="#module-Fut" class="anchor"></a><code><span><span class="keyword">module</span> Fut</span><span> = <a href="../../moonpool/Moonpool/Fut/index.html">Moonpool.Fut</a></span></code></div></div><h3 id="basic-conversions"><a href="#basic-conversions" class="anchor"></a>Basic conversions</h3><div class="odoc-spec"><div class="spec value anchored" id="val-fut_of_lwt"><a href="#val-fut_of_lwt" class="anchor"></a><code><span><span class="keyword">val</span> fut_of_lwt : <span><span><span class="type-var">'a</span> <a href="../../lwt/Lwt/index.html#type-t">Lwt.t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <a href="../../moonpool/Moonpool/Fut/index.html#type-t">Moonpool.Fut.t</a></span></span></code></div><div class="spec-doc"><p><code>fut_of_lwt lwt_fut</code> makes a thread-safe moonpool future that completes when <code>lwt_fut</code> does. This can be run from any thread.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-lwt_of_fut"><a href="#val-lwt_of_fut" class="anchor"></a><code><span><span class="keyword">val</span> lwt_of_fut : <span><span><span class="type-var">'a</span> <a href="../../moonpool/Moonpool/Fut/index.html#type-t">Moonpool.Fut.t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <a href="../../lwt/Lwt/index.html#type-t">Lwt.t</a></span></span></code></div><div class="spec-doc"><p><code>lwt_of_fut fut</code> makes a lwt future that completes when <code>fut</code> does. This must be called from the Lwt thread, and the result must always be used only from inside the Lwt thread.</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <code>Failure</code> <p>if not run from the lwt thread.</p></li></ul></div></div><h3 id="helpers-on-the-moonpool-side"><a href="#helpers-on-the-moonpool-side" class="anchor"></a>Helpers on the moonpool side</h3><div class="odoc-spec"><div class="spec value anchored" id="val-spawn_lwt"><a href="#val-spawn_lwt" class="anchor"></a><code><span><span class="keyword">val</span> spawn_lwt : <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="../../lwt/Lwt/index.html#type-t">Lwt.t</a></span></span></code></div><div class="spec-doc"><p>This spawns a task that runs in the Lwt scheduler. This function is thread safe.</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <code>Failure</code> <p>if <a href="#val-lwt_main"><code>lwt_main</code></a> was not called.</p></li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-spawn_lwt_ignore"><a href="#val-spawn_lwt_ignore" class="anchor"></a><code><span><span class="keyword">val</span> spawn_lwt_ignore : <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>Like <a href="#val-spawn_lwt"><code>spawn_lwt</code></a> but ignores the result, like <code>Lwt.async</code>. This function is thread safe.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-await_lwt"><a href="#val-await_lwt" class="anchor"></a><code><span><span class="keyword">val</span> await_lwt : <span><span><span class="type-var">'a</span> <a href="../../lwt/Lwt/index.html#type-t">Lwt.t</a></span> <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'a</span></span></code></div><div class="spec-doc"><p><code>await_lwt fut</code> awaits a Lwt future from inside a task running on a moonpool runner. This must be run from within a Moonpool runner so that the await-ing effect is handled, but it doesn't have to run from inside the Lwt thread.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-run_in_lwt_and_await"><a href="#val-run_in_lwt_and_await" class="anchor"></a><code><span><span class="keyword">val</span> run_in_lwt_and_await : <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 class="type-var">'a</span></span></code></div><div class="spec-doc"><p><code>run_in_lwt_and_await f</code> runs <code>f()</code> in the lwt thread, just like <code>spawn_lwt f</code>, and then calls <a href="#val-await_lwt"><code>await_lwt</code></a> on the result. This means <code>f()</code> can use Lwt functions and libraries, use <a href="#val-await_lwt"><code>await_lwt</code></a> on them freely, etc.</p><p>This function must run from within a task running on a moonpool runner so that it can <code>await_lwt</code>.</p></div></div><h3 id="wrappers-around-lwt_main"><a href="#wrappers-around-lwt_main" class="anchor"></a>Wrappers around Lwt_main</h3><div class="odoc-spec"><div class="spec value anchored" id="val-on_uncaught_exn"><a href="#val-on_uncaught_exn" class="anchor"></a><code><span><span class="keyword">val</span> on_uncaught_exn : <span><span>(<span><a href="../../moonpool/Moonpool/Exn_bt/index.html#type-t">Moonpool.Exn_bt.t</a> <span class="arrow">&#45;&gt;</span></span> unit)</span> <a href="../../ocaml/Stdlib/index.html#type-ref">ref</a></span></span></code></div><div class="spec-doc"><p>Exception handler for tasks that raise an uncaught exception.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-lwt_main"><a href="#val-lwt_main" class="anchor"></a><code><span><span class="keyword">val</span> lwt_main : <span><span>(<span><a href="../../moonpool/Moonpool/Runner/index.html#type-t">Moonpool.Runner.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>lwt_main f</code> sets the moonpool-lwt bridge up, runs lwt main, calls <code>f</code>, destroys the bridge, and return the result of <code>f()</code>. Only one thread should call this at a time.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-on_lwt_thread"><a href="#val-on_lwt_thread" class="anchor"></a><code><span><span class="keyword">val</span> on_lwt_thread : <span>unit <span class="arrow">&#45;&gt;</span></span> bool</span></code></div><div class="spec-doc"><p><code>on_lwt_thread ()</code> is true if the current thread is the one currently running <a href="#val-lwt_main"><code>lwt_main</code></a>. This is thread safe.</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <code>Failure</code> <p>if <a href="#val-lwt_main"><code>lwt_main</code></a> was not called.</p></li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-lwt_main_runner"><a href="#val-lwt_main_runner" class="anchor"></a><code><span><span class="keyword">val</span> lwt_main_runner : <span>unit <span class="arrow">&#45;&gt;</span></span> <a href="../../moonpool/Moonpool/Runner/index.html#type-t">Moonpool.Runner.t</a></span></code></div><div class="spec-doc"><p>The runner from <a href="#val-lwt_main"><code>lwt_main</code></a>. The runner is only going to work if <a href="#val-lwt_main"><code>lwt_main</code></a> is currently running in some thread. This is thread safe.</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <code>Failure</code> <p>if <a href="#val-lwt_main"><code>lwt_main</code></a> was not called.</p></li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-is_setup"><a href="#val-is_setup" class="anchor"></a><code><span><span class="keyword">val</span> is_setup : <span>unit <span class="arrow">&#45;&gt;</span></span> bool</span></code></div><div class="spec-doc"><p>Is the moonpool-lwt bridge setup? This is thread safe.</p></div></div></div></body></html>