linol/lwt/Lwt_timeout/index.html
2025-08-24 01:27:17 +00:00

2 lines
4.3 KiB
HTML
Raw Permalink 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_timeout (lwt.Lwt_timeout)</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_timeout</nav><header class="odoc-preamble"><h1>Module <code><span>Lwt_timeout</span></code></h1><p>Cancelable timeouts.</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><div class="odoc-spec"><div class="spec value anchored" id="val-create"><a href="#val-create" class="anchor"></a><code><span><span class="keyword">val</span> create : <span>int <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> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p><code>Lwt_timeout.create n f</code> creates a new timeout object with duration <code>n</code> seconds. <code>f</code> is the <em>action</em>, a function to be called once the timeout expires. <code>f</code> should not raise exceptions.</p><p>The timeout is not started until <a href="#val-start"><code>Lwt_timeout.start</code></a> is called on it.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-start"><a href="#val-start" class="anchor"></a><code><span><span class="keyword">val</span> start : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p>Starts the given timeout.</p><p>Starting a timeout that has already been started has the same effect as stopping it, and then restarting it with its original duration. So, suppose you have <code>timeout</code> with a duration of three seconds, which was started two seconds ago. The next call to its action is scheduled for one second in the future. Calling <code>Lwt_timeout.start timeout</code> at this point cancels this upcoming action call, and schedules a call three seconds from now.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-stop"><a href="#val-stop" class="anchor"></a><code><span><span class="keyword">val</span> stop : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p>Stops (cancels) the given timeout.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-change"><a href="#val-change" class="anchor"></a><code><span><span class="keyword">val</span> change : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <span>int <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p>Changes the duration of the given timeout.</p><p>If the timeout has already been started, it is stopped, and restarted with its new duration. This is similar to how <a href="#val-start"><code>Lwt_timeout.start</code></a> works on a timeout that has already been started.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-set_exn_handler"><a href="#val-set_exn_handler" class="anchor"></a><code><span><span class="keyword">val</span> set_exn_handler : <span><span>(<span>exn <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>Lwt_timeout.set_exn_handler f</code> sets the handler to be used for exceptions raised by timeout actions. Recall that actions are not allowed to raise exceptions. If they do raise an exception <code>exn</code> despite this, <code>f exn</code> is called.</p><p>The default behavior of <code>f exn</code>, set by <code>Lwt_timeout</code> on program startup, is to pass <code>exn</code> to <code>!</code><a href="../Lwt/index.html#val-async_exception_hook"><code>Lwt.async_exception_hook</code></a>. The default behavior of <em>that</em> is to terminate the process.</p></div></div></div></body></html>