moonpool/lwt/Lwt_engine/index.html
2025-09-26 19:08:06 +00:00

2 lines
13 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>Lwt_engine (lwt.Lwt_engine)</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">lwt</a> &#x00BB; Lwt_engine</nav><header class="odoc-preamble"><h1>Module <code><span>Lwt_engine</span></code></h1><p>Lwt unix main loop engine</p></header><div class="odoc-tocs"><nav class="odoc-toc odoc-local-toc"><ul><li><a href="#events">Events</a></li><li><a href="#event-loop-functions">Event loop functions</a></li><li><a href="#engines">Engines</a></li><li><a href="#predefined-engines">Predefined engines</a></li><li><a href="#the-current-engine">The current engine</a></li></ul></nav></div><div class="odoc-content"><h3 id="events"><a href="#events" class="anchor"></a>Events</h3><div class="odoc-spec"><div class="spec type anchored" id="type-event"><a href="#type-event" class="anchor"></a><code><span><span class="keyword">type</span> event</span></code></div><div class="spec-doc"><p>Type of events. An event represent a callback registered to be called when some event occurs.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-stop_event"><a href="#val-stop_event" class="anchor"></a><code><span><span class="keyword">val</span> stop_event : <span><a href="#type-event">event</a> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p><code>stop_event event</code> stops the given event.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-fake_event"><a href="#val-fake_event" class="anchor"></a><code><span><span class="keyword">val</span> fake_event : <a href="#type-event">event</a></span></code></div><div class="spec-doc"><p>Event which does nothing when stopped.</p></div></div><h3 id="event-loop-functions"><a href="#event-loop-functions" class="anchor"></a>Event loop functions</h3><div class="odoc-spec"><div class="spec value anchored" id="val-iter"><a href="#val-iter" class="anchor"></a><code><span><span class="keyword">val</span> iter : <span>bool <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p><code>iter block</code> performs one iteration of the main loop. If <code>block</code> is <code>true</code> the function must block until one event becomes available, otherwise it should just check for available events and return immediately.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-on_readable"><a href="#val-on_readable" class="anchor"></a><code><span><span class="keyword">val</span> on_readable : <span><a href="../../ocaml/Unix/index.html#type-file_descr">Unix.file_descr</a> <span class="arrow">&#45;&gt;</span></span> <span><span>(<span><a href="#type-event">event</a> <span class="arrow">&#45;&gt;</span></span> unit)</span> <span class="arrow">&#45;&gt;</span></span> <a href="#type-event">event</a></span></code></div><div class="spec-doc"><p><code>on_readable fd f</code> calls <code>f</code> each time <code>fd</code> becomes readable.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-on_writable"><a href="#val-on_writable" class="anchor"></a><code><span><span class="keyword">val</span> on_writable : <span><a href="../../ocaml/Unix/index.html#type-file_descr">Unix.file_descr</a> <span class="arrow">&#45;&gt;</span></span> <span><span>(<span><a href="#type-event">event</a> <span class="arrow">&#45;&gt;</span></span> unit)</span> <span class="arrow">&#45;&gt;</span></span> <a href="#type-event">event</a></span></code></div><div class="spec-doc"><p><code>on_readable fd f</code> calls <code>f</code> each time <code>fd</code> becomes writable.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-on_timer"><a href="#val-on_timer" class="anchor"></a><code><span><span class="keyword">val</span> on_timer : <span>float <span class="arrow">&#45;&gt;</span></span> <span>bool <span class="arrow">&#45;&gt;</span></span> <span><span>(<span><a href="#type-event">event</a> <span class="arrow">&#45;&gt;</span></span> unit)</span> <span class="arrow">&#45;&gt;</span></span> <a href="#type-event">event</a></span></code></div><div class="spec-doc"><p><code>on_timer delay repeat f</code> calls <code>f</code> one time after <code>delay</code> seconds. If <code>repeat</code> is <code>true</code> then <code>f</code> is called each <code>delay</code> seconds, otherwise it is called only one time.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-readable_count"><a href="#val-readable_count" class="anchor"></a><code><span><span class="keyword">val</span> readable_count : <span>unit <span class="arrow">&#45;&gt;</span></span> int</span></code></div><div class="spec-doc"><p>Returns the number of events waiting for a file descriptor to become readable.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-writable_count"><a href="#val-writable_count" class="anchor"></a><code><span><span class="keyword">val</span> writable_count : <span>unit <span class="arrow">&#45;&gt;</span></span> int</span></code></div><div class="spec-doc"><p>Returns the number of events waiting for a file descriptor to become writable.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-timer_count"><a href="#val-timer_count" class="anchor"></a><code><span><span class="keyword">val</span> timer_count : <span>unit <span class="arrow">&#45;&gt;</span></span> int</span></code></div><div class="spec-doc"><p>Returns the number of registered timers.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-fake_io"><a href="#val-fake_io" class="anchor"></a><code><span><span class="keyword">val</span> fake_io : <span><a href="../../ocaml/Unix/index.html#type-file_descr">Unix.file_descr</a> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p>Simulates activity on the given file descriptor.</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>unit <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p>Called internally by Lwt_unix.fork to make sure we don't get strange behaviour</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-forwards_signal"><a href="#val-forwards_signal" class="anchor"></a><code><span><span class="keyword">val</span> forwards_signal : <span>int <span class="arrow">&#45;&gt;</span></span> bool</span></code></div><div class="spec-doc"><p><code>forwards_signal signum</code> is <code>true</code> if the engine will call <a href="../Lwt_unix/index.html#val-handle_signal"><code>Lwt_unix.handle_signal</code></a> when signal <code>signum</code> occurs. In this case, Lwt will not install its own signal handler.</p><p>Normally, this just returns <code>false</code>, but when Lwt is used in combination with other IO libraries, this allows sharing e.g. the SIGCHLD handler.</p></div></div><h3 id="engines"><a href="#engines" class="anchor"></a>Engines</h3><p>An engine represents a set of functions used to register different kinds of callbacks for different kinds of events.</p><div class="odoc-spec"><div class="spec class anchored" id="class-abstract"><a href="#class-abstract" class="anchor"></a><code><span><span class="keyword">class</span> <span class="keyword">virtual</span> </span><span><a href="class-abstract/index.html">abstract</a></span><span> : <span class="keyword">object</span> ... <span class="keyword">end</span></span></code></div><div class="spec-doc"><p>Abstract class for engines.</p></div></div><div class="odoc-spec"><div class="spec class-type anchored" id="class-type-t"><a href="#class-type-t" class="anchor"></a><code><span><span class="keyword">class</span> <span class="keyword">type</span> </span><span><a href="class-type-t/index.html">t</a></span><span> = <span class="keyword">object</span> ... <span class="keyword">end</span></span></code></div><div class="spec-doc"><p>Type of engines.</p></div></div><h3 id="predefined-engines"><a href="#predefined-engines" class="anchor"></a>Predefined engines</h3><div class="odoc-spec"><div class="spec type anchored" id="type-ev_loop"><a href="#type-ev_loop" class="anchor"></a><code><span><span class="keyword">type</span> ev_loop</span></code></div></div><div class="odoc-spec"><div class="spec module anchored" id="module-Ev_backend"><a href="#module-Ev_backend" class="anchor"></a><code><span><span class="keyword">module</span> <a href="Ev_backend/index.html">Ev_backend</a></span><span> : <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div></div><p>Type of libev loops.</p><div class="odoc-spec"><div class="spec class anchored" id="class-libev"><a href="#class-libev" class="anchor"></a><code><span><span class="keyword">class</span> </span><span><a href="class-libev/index.html">libev</a></span><span> : <span><span class="optlabel">?backend</span>:<a href="Ev_backend/index.html#type-t">Ev_backend.t</a> <span class="arrow">&#45;&gt;</span></span> <span>unit <span class="arrow">&#45;&gt;</span></span> <span class="keyword">object</span> ... <span class="keyword">end</span></span></code></div><div class="spec-doc"><p>Engine based on libev. If not compiled with libev support, the creation of the class will raise <a href="../Lwt_sys/index.html#exception-Not_available"><code>Lwt_sys.Not_available</code></a>.</p></div></div><div class="odoc-spec"><div class="spec class anchored" id="class-select"><a href="#class-select" class="anchor"></a><code><span><span class="keyword">class</span> </span><span><a href="class-select/index.html">select</a></span><span> : <a href="class-type-t/index.html">t</a></span></code></div><div class="spec-doc"><p>Engine based on <a href="../../ocaml/Unix/index.html#val-select"><code>Unix.select</code></a>.</p></div></div><div class="odoc-spec"><div class="spec class anchored" id="class-select_based"><a href="#class-select_based" class="anchor"></a><code><span><span class="keyword">class</span> <span class="keyword">virtual</span> </span><span><a href="class-select_based/index.html">select_based</a></span><span> : <span class="keyword">object</span> ... <span class="keyword">end</span></span></code></div><div class="spec-doc"><p>Abstract class for engines based on a select-like function.</p></div></div><div class="odoc-spec"><div class="spec class anchored" id="class-poll_based"><a href="#class-poll_based" class="anchor"></a><code><span><span class="keyword">class</span> <span class="keyword">virtual</span> </span><span><a href="class-poll_based/index.html">poll_based</a></span><span> : <span class="keyword">object</span> ... <span class="keyword">end</span></span></code></div><div class="spec-doc"><p>Abstract class for engines based on a poll-like function.</p></div></div><h3 id="the-current-engine"><a href="#the-current-engine" class="anchor"></a>The current engine</h3><div class="odoc-spec"><div class="spec value anchored" id="val-get"><a href="#val-get" class="anchor"></a><code><span><span class="keyword">val</span> get : <span>unit <span class="arrow">&#45;&gt;</span></span> <a href="class-type-t/index.html">t</a></span></code></div><div class="spec-doc"><p><code>get ()</code> returns the engine currently in use.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-set"><a href="#val-set" class="anchor"></a><code><span><span class="keyword">val</span> set : <span><span class="optlabel">?transfer</span>:bool <span class="arrow">&#45;&gt;</span></span> <span><span class="optlabel">?destroy</span>:bool <span class="arrow">&#45;&gt;</span></span> <span><a href="class-type-t/index.html">t</a> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p><code>set ?transfer ?destroy engine</code> replaces the current engine by the given one.</p><p>If <code>transfer</code> is <code>true</code> (the default) all events from the current engine are transferred to the new one.</p><p>If <code>destroy</code> is <code>true</code> (the default) then the current engine is destroyed before being replaced.</p></div></div><div class="odoc-spec"><div class="spec module anchored" id="module-Versioned"><a href="#module-Versioned" class="anchor"></a><code><span><span class="keyword">module</span> <a href="Versioned/index.html">Versioned</a></span><span> : <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div></div></div></body></html>