nanoev/picos/Picos/Handler/index.html
2025-05-05 14:16:16 +00:00

7 lines
5.7 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>Handler (picos.Picos.Handler)</title><meta charset="utf-8"/><link rel="stylesheet" href="../../../_odoc-theme/odoc.css"/><meta name="generator" content="odoc 3.0.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</a> &#x00BB; <a href="../index.html">Picos</a> &#x00BB; Handler</nav><header class="odoc-preamble"><h1>Module <code><span>Picos.Handler</span></code></h1><p>Handler for the effects based operations of Picos for OCaml 4.</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> <span>'c t</span></span><span> = </span><span>{</span></code><ol><li id="type-t.current" class="def record field anchored"><a href="#type-t.current" class="anchor"></a><code><span>current : <span><span class="type-var">'c</span> <span class="arrow">&#45;&gt;</span></span> <a href="../Fiber/index.html#type-t">Fiber.t</a>;</span></code><div class="def-doc"><span class="comment-delim">(*</span><p>See <a href="../Fiber/index.html#val-current"><code>Picos.Fiber.current</code></a>.</p><span class="comment-delim">*)</span></div></li><li id="type-t.spawn" class="def record field anchored"><a href="#type-t.spawn" class="anchor"></a><code><span>spawn : <span><span class="type-var">'c</span> <span class="arrow">&#45;&gt;</span></span> <span><a href="../Fiber/index.html#type-t">Fiber.t</a> <span class="arrow">&#45;&gt;</span></span> <span><span>(<span><a href="../Fiber/index.html#type-t">Fiber.t</a> <span class="arrow">&#45;&gt;</span></span> unit)</span> <span class="arrow">&#45;&gt;</span></span> unit;</span></code><div class="def-doc"><span class="comment-delim">(*</span><p>See <a href="../Fiber/index.html#val-spawn"><code>Picos.Fiber.spawn</code></a>.</p><span class="comment-delim">*)</span></div></li><li id="type-t.yield" class="def record field anchored"><a href="#type-t.yield" class="anchor"></a><code><span>yield : <span><span class="type-var">'c</span> <span class="arrow">&#45;&gt;</span></span> unit;</span></code><div class="def-doc"><span class="comment-delim">(*</span><p>See <a href="../Fiber/index.html#val-yield"><code>Picos.Fiber.yield</code></a>.</p><span class="comment-delim">*)</span></div></li><li id="type-t.cancel_after" class="def record field anchored"><a href="#type-t.cancel_after" class="anchor"></a><code><span>cancel_after : 'a. <span><span class="type-var">'c</span> <span class="arrow">&#45;&gt;</span></span>
<span><span><span class="type-var">'a</span> <a href="../Computation/index.html#type-t">Computation.t</a></span> <span class="arrow">&#45;&gt;</span></span>
<span><span class="label">seconds</span>:float <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 class="def-doc"><span class="comment-delim">(*</span><p>See <a href="../Computation/index.html#val-cancel_after"><code>Picos.Computation.cancel_after</code></a>.</p><span class="comment-delim">*)</span></div></li><li id="type-t.await" class="def record field anchored"><a href="#type-t.await" class="anchor"></a><code><span>await : <span><span class="type-var">'c</span> <span class="arrow">&#45;&gt;</span></span> <span><a href="../Trigger/index.html#type-t">Trigger.t</a> <span class="arrow">&#45;&gt;</span></span> <span><span>(exn * <a href="../../../ocaml/Stdlib/Printexc/index.html#type-raw_backtrace">Stdlib.Printexc.raw_backtrace</a>)</span> option</span>;</span></code><div class="def-doc"><span class="comment-delim">(*</span><p>See <a href="../Trigger/index.html#val-await"><code>Picos.Trigger.await</code></a>.</p><span class="comment-delim">*)</span></div></li></ol><code><span>}</span></code></div><div class="spec-doc"><p>A record of implementations of the primitive effects based operations of Picos. The operations take a context of type <code>'c</code> as an argument.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-using"><a href="#val-using" class="anchor"></a><code><span><span class="keyword">val</span> using : <span><span><span class="type-var">'c</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'c</span> <span class="arrow">&#45;&gt;</span></span> <span><span>(<span><a href="../Fiber/index.html#type-t">Fiber.t</a> <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>using handler context main</code> sets the <code>handler</code> and the <code>context</code> for the handler of the primitive effects based operations of Picos while running <code>main</code>.</p><p> The behavior is that</p><ul><li>on OCaml 4, <code>using</code> stores the <code>handler</code> in <a href="../../Picos_thread/TLS/index.html" title="Picos_thread.TLS"><code>TLS</code></a>, which allows the operations to be accessed during the execution of the <code>thunk</code>, and</li><li>on OCaml 5, <code>using</code> runs <code>thunk</code> with a deep effect handler that delegates to the operations of the <code>handler</code>.</li></ul><p>⚠️ While this works on OCaml 5, you usually want to use a scheduler that implements an effect handler directly, because that is likely to perform better.</p></div></div></div></body></html>