mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-06 03:05:30 -05:00
2 lines
10 KiB
HTML
2 lines
10 KiB
HTML
<!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> » <a href="../index.html">moonpool-lwt</a> » 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 "lwt thread" the thread running <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></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="#io">IO</a></li><li><a href="#helpers-on-the-lwt-side">Helpers on the lwt 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-Fiber"><a href="#module-Fiber" class="anchor"></a><code><span><span class="keyword">module</span> Fiber</span><span> = <a href="../../moonpool/Moonpool_fib/Fiber/index.html">Moonpool_fib.Fiber</a></span></code></div></div><div class="odoc-spec"><div class="spec module anchored" id="module-FLS"><a href="#module-FLS" class="anchor"></a><code><span><span class="keyword">module</span> FLS</span><span> = <a href="../../moonpool/Moonpool_fib/Fls/index.html">Moonpool_fib.Fls</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">-></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 must be run from within the Lwt 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">-></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></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-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">-></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.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-run_in_lwt"><a href="#val-run_in_lwt" class="anchor"></a><code><span><span class="keyword">val</span> run_in_lwt : <span><span>(<span>unit <span class="arrow">-></span></span> <span><span class="type-var">'a</span> <a href="../../lwt/Lwt/index.html#type-t">Lwt.t</a></span>)</span> <span class="arrow">-></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>run_in_lwt f</code> runs <code>f()</code> from within the Lwt thread and returns a thread-safe future. This can be run from anywhere.</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">-></span></span> <span><span class="type-var">'a</span> <a href="../../lwt/Lwt/index.html#type-t">Lwt.t</a></span>)</span> <span class="arrow">-></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, and awaits its result. Must be run from inside a moonpool runner so that the await-in effect is handled.</p><p>This is similar to <code>Moonpool.await @@ run_in_lwt f</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-get_runner"><a href="#val-get_runner" class="anchor"></a><code><span><span class="keyword">val</span> get_runner : <span>unit <span class="arrow">-></span></span> <a href="../../moonpool/Moonpool/Runner/index.html#type-t">Moonpool.Runner.t</a></span></code></div><div class="spec-doc"><p>Returns the runner from within which this is called. Must be run from within a fiber.</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <code>Failure</code> <p>if not run within a fiber</p></li></ul></div></div><h3 id="io"><a href="#io" class="anchor"></a>IO</h3><div class="odoc-spec"><div class="spec module anchored" id="module-IO"><a href="#module-IO" class="anchor"></a><code><span><span class="keyword">module</span> <a href="IO/index.html">IO</a></span><span> : <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div><div class="spec-doc"><p>IO using the Lwt event loop.</p></div></div><div class="odoc-spec"><div class="spec module anchored" id="module-IO_in"><a href="#module-IO_in" class="anchor"></a><code><span><span class="keyword">module</span> <a href="IO_in/index.html">IO_in</a></span><span> : <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div><div class="spec-doc"><p>Input channel</p></div></div><div class="odoc-spec"><div class="spec module anchored" id="module-IO_out"><a href="#module-IO_out" class="anchor"></a><code><span><span class="keyword">module</span> <a href="IO_out/index.html">IO_out</a></span><span> : <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div><div class="spec-doc"><p>Output channel</p></div></div><div class="odoc-spec"><div class="spec module anchored" id="module-TCP_server"><a href="#module-TCP_server" class="anchor"></a><code><span><span class="keyword">module</span> <a href="TCP_server/index.html">TCP_server</a></span><span> : <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div></div><div class="odoc-spec"><div class="spec module anchored" id="module-TCP_client"><a href="#module-TCP_client" class="anchor"></a><code><span><span class="keyword">module</span> <a href="TCP_client/index.html">TCP_client</a></span><span> : <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div></div><h3 id="helpers-on-the-lwt-side"><a href="#helpers-on-the-lwt-side" class="anchor"></a>Helpers on the lwt side</h3><div class="odoc-spec"><div class="spec value anchored" id="val-detach_in_runner"><a href="#val-detach_in_runner" class="anchor"></a><code><span><span class="keyword">val</span> detach_in_runner : <span><span class="label">runner</span>:<a href="../../moonpool/Moonpool/Runner/index.html#type-t">Moonpool.Runner.t</a> <span class="arrow">-></span></span> <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="../../lwt/Lwt/index.html#type-t">Lwt.t</a></span></span></code></div><div class="spec-doc"><p><code>detach_in_runner ~runner f</code> runs <code>f</code> in the given moonpool runner, and returns a lwt future. This must be run from within the thread running <code>Lwt_main</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-main_with_runner"><a href="#val-main_with_runner" class="anchor"></a><code><span><span class="keyword">val</span> main_with_runner : <span><span class="label">runner</span>:<a href="../../moonpool/Moonpool/Runner/index.html#type-t">Moonpool.Runner.t</a> <span class="arrow">-></span></span> <span><span>(<span>unit <span class="arrow">-></span></span> <span class="type-var">'a</span>)</span> <span class="arrow">-></span></span> <span class="type-var">'a</span></span></code></div><div class="spec-doc"><p><code>main_with_runner ~runner f</code> starts a Lwt-based event loop and runs <code>f()</code> inside a fiber in <code>runner</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-main"><a href="#val-main" class="anchor"></a><code><span><span class="keyword">val</span> main : <span><span>(<span>unit <span class="arrow">-></span></span> <span class="type-var">'a</span>)</span> <span class="arrow">-></span></span> <span class="type-var">'a</span></span></code></div><div class="spec-doc"><p>Like <a href="#val-main_with_runner"><code>main_with_runner</code></a> but with a default choice of runner.</p></div></div></div></body></html>
|