Packages

Boa-powered JavaScript runtimes for Elixir with BEAM dispatch hooks.

Current section

Files

Jump to
boam doc Boam.Dispatcher.html
Raw

doc/Boam.Dispatcher.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="ExDoc v0.40.1">
<meta name="project" content="boam v0.1.3">
<title>Boam.Dispatcher — boam v0.1.3</title>
<link rel="stylesheet" href="dist/html-elixir-YJO4MOOW.css" />
<script defer src="dist/sidebar_items-4C4FEE2F.js"></script>
<script defer src="docs_config.js"></script>
<script defer src="dist/html-YU4BZFVS.js"></script>
</head>
<body>
<script>(()=>{var t="ex_doc:settings",e="dark";var o="dark",s="light";var E="sidebar_state",n="closed";var r="sidebar_width";var a="sidebar-open";var i=new URLSearchParams(window.location.search),S=i.get("theme")||JSON.parse(localStorage.getItem(t)||"{}").theme;(S===o||S!==s&&window.matchMedia("(prefers-color-scheme: dark)").matches)&&document.body.classList.add(e);var d=sessionStorage.getItem(E),A=d!==n&&!window.matchMedia(`screen and (max-width: ${768}px)`).matches;document.body.classList.toggle(a,A);var c=sessionStorage.getItem(r);c&&document.body.style.setProperty("--sidebarWidth",`${c}px`);var p=/(Macintosh|iPhone|iPad|iPod)/.test(window.navigator.userAgent);document.documentElement.classList.toggle("apple-os",p);})();
</script>
<div class="body-wrapper">
<button id="sidebar-menu" class="sidebar-button sidebar-toggle" aria-label="toggle sidebar" aria-controls="sidebar">
<i class="ri-menu-line ri-lg" title="Collapse/expand sidebar"></i>
</button>
<nav id="sidebar" class="sidebar">
<div class="sidebar-header">
<div class="sidebar-projectInfo">
<div>
<a href="readme.html" class="sidebar-projectName" translate="no">
boam
</a>
<div class="sidebar-projectVersion" translate="no">
v0.1.3
</div>
</div>
</div>
<ul id="sidebar-list-nav" class="sidebar-list-nav" role="tablist" data-extras="Pages"></ul>
</div>
</nav>
<output role="status" id="toast"></output>
<main class="content page-module" id="main" data-type="modules">
<div id="content" class="content-inner">
<div class="top-search">
<div class="search-settings">
<form class="search-bar" action="search.html">
<label class="search-label">
<span class="sr-only">Search documentation of boam</span>
<div class="search-input-wrapper">
<input name="q" type="text" class="search-input" placeholder="Press / to search" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" />
<button type="button" tabindex="-1" class="search-close-button" aria-hidden="true">
<i class="ri-close-line ri-lg" title="Cancel search"></i>
</button>
</div>
</label>
</form>
<div class="autocomplete">
</div>
<div class="engine-selector" data-multiple="false">
<button type="button" class="engine-button" aria-label="Select search engine" aria-haspopup="true" aria-expanded="false">
<i class="ri-search-2-line" aria-hidden="true"></i>
<span class="engine-name">Default</span>
<i class="ri-arrow-down-s-line" aria-hidden="true"></i>
</button>
<div class="engine-dropdown" hidden role="menu">
<button type="button"
class="engine-option"
data-engine-url="search.html?q="
role="menuitemradio"
aria-checked="true">
<span class="name">Default</span>
<span class="help">In-browser search</span>
</button>
</div>
</div>
<button class="icon-settings display-settings">
<i class="ri-settings-3-line"></i>
<span class="sr-only">Settings</span>
</button>
</div>
</div>
<div id="top-content">
<div class="heading-with-actions top-heading">
<h1>
<span translate="no">Boam.<wbr>Dispatcher</span>
<small class="app-vsn" translate="no">(boam v0.1.3)</small>
</h1>
<a href="Boam.Dispatcher.md" title="Copy Markdown (hold Ctrl/Cmd and click it to open as Markdown)" class="copy-markdown icon-action" rel="help">
<i class="ri-markdown-line" aria-hidden="true"></i>
<span class="sr-only">Copy Markdown</span>
</a>
</div>
<section id="moduledoc">
<p>Dispatch process for <code class="inline">beam.call(...)</code> requests originating in JavaScript.</p><p>A dispatcher is an ordinary <a href="https://hexdocs.pm/elixir/GenServer.html"><code class="inline">GenServer</code></a> that receives messages from the Rust
runtime, resolves the requested handler, executes it on the BEAM, and replies
back to the waiting JavaScript call.</p><p>In the default setup you do not need to start this module manually;
<a href="Boam.Runtime.html"><code class="inline">Boam.Runtime</code></a> starts one automatically when no explicit
<code class="inline">:dispatcher</code> pid is supplied.</p><h2 id="module-handler-forms" class="section-heading"><a href="#module-handler-forms" class="hover-link"><i class="ri-link-m" aria-hidden="true"></i></a><span class="text">Handler Forms</span></h2><p>Handlers can be provided in three shapes:</p><ul><li><code class="inline">fn args -&gt; result end</code></li><li><code class="inline">fn name, args -&gt; result end</code></li><li><code class="inline">{Module, :function}</code> which is called as <code class="inline">apply(Module, :function, [args])</code></li></ul><h2 id="module-return-contract" class="section-heading"><a href="#module-return-contract" class="hover-link"><i class="ri-link-m" aria-hidden="true"></i></a><span class="text">Return Contract</span></h2><p>A handler may return:</p><ul><li>any JSON-compatible value, which becomes the JavaScript return value</li><li><code class="inline">{:ok, value}</code>, which unwraps to <code class="inline">value</code></li><li><code class="inline">{:error, reason}</code>, which raises a JavaScript error</li></ul><p>If a handler crashes, the formatted exception is sent back as a JavaScript
error message instead of leaving the runtime hanging.</p>
</section>
</div>
<section id="summary" class="details-list">
<h2 class="section-heading">
<a class="hover-link" href="#summary">
<i class="ri-link-m" aria-hidden="true"></i>
</a>
<span class="text">Summary</span>
</h2>
<div class="summary-types summary">
<h3>
<a href="#types">Types</a>
</h3>
<div class="summary-row">
<div class="summary-signature">
<a href="#t:export_name/0" data-no-tooltip="" translate="no">export_name()</a>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#t:handler/0" data-no-tooltip="" translate="no">handler()</a>
</div>
<div class="summary-synopsis"><p>Function or MFA that can satisfy a <code class="inline">beam.call(...)</code> request.</p></div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#t:start_option/0" data-no-tooltip="" translate="no">start_option()</a>
</div>
</div>
</div>
<div class="summary-functions summary">
<h3>
<a href="#functions">Functions</a>
</h3>
<div class="summary-row">
<div class="summary-signature">
<a href="#child_spec/1" data-no-tooltip="" translate="no">child_spec(init_arg)</a>
</div>
<div class="summary-synopsis"><p>Returns a specification to start this module under a supervisor.</p></div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#start_link/1" data-no-tooltip="" translate="no">start_link(opts \\ [])</a>
</div>
<div class="summary-synopsis"><p>Starts a dispatcher process.</p></div>
</div>
</div>
</section>
<section id="types" class="details-list">
<h2 class="section-heading">
<a class="hover-link" href="#types">
<i class="ri-link-m" aria-hidden="true"></i>
</a>
<span class="text">Types</span>
</h2>
<div class="types-list">
<section class="detail" id="t:export_name/0">
<div class="detail-header">
<a href="#t:export_name/0" class="detail-link" data-no-tooltip="" aria-label="Link to this type">
<i class="ri-link-m" aria-hidden="true"></i>
</a>
<div class="heading-with-actions">
<h1 class="signature" translate="no">export_name()</h1>
</div>
</div>
<section class="docstring">
<div class="specs">
<pre translate="no"><span class="attribute">@type</span> export_name() :: <a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">atom</a>() | <a href="https://hexdocs.pm/elixir/String.html#t:t/0">String.t</a>()</pre>
</div>
</section>
</section>
<section class="detail" id="t:handler/0">
<div class="detail-header">
<a href="#t:handler/0" class="detail-link" data-no-tooltip="" aria-label="Link to this type">
<i class="ri-link-m" aria-hidden="true"></i>
</a>
<div class="heading-with-actions">
<h1 class="signature" translate="no">handler()</h1>
</div>
</div>
<section class="docstring">
<div class="specs">
<pre translate="no"><span class="attribute">@type</span> handler() ::
(<a href="https://hexdocs.pm/elixir/typespecs.html#built-in-types">list</a>() -&gt; <a href="https://hexdocs.pm/elixir/typespecs.html#built-in-types">term</a>()) | (<a href="https://hexdocs.pm/elixir/String.html#t:t/0">String.t</a>(), <a href="https://hexdocs.pm/elixir/typespecs.html#built-in-types">list</a>() -&gt; <a href="https://hexdocs.pm/elixir/typespecs.html#built-in-types">term</a>()) | {<a href="https://hexdocs.pm/elixir/typespecs.html#built-in-types">module</a>(), <a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">atom</a>()}</pre>
</div>
<p>Function or MFA that can satisfy a <code class="inline">beam.call(...)</code> request.</p>
</section>
</section>
<section class="detail" id="t:start_option/0">
<div class="detail-header">
<a href="#t:start_option/0" class="detail-link" data-no-tooltip="" aria-label="Link to this type">
<i class="ri-link-m" aria-hidden="true"></i>
</a>
<div class="heading-with-actions">
<h1 class="signature" translate="no">start_option()</h1>
</div>
</div>
<section class="docstring">
<div class="specs">
<pre translate="no"><span class="attribute">@type</span> start_option() ::
{:name, <a href="https://hexdocs.pm/elixir/GenServer.html#t:name/0">GenServer.name</a>()}
| {:exports, %{optional(<a href="#t:export_name/0">export_name</a>()) =&gt; <a href="#t:handler/0">handler</a>()} | <a href="https://hexdocs.pm/elixir/typespecs.html#built-in-types">keyword</a>(<a href="#t:handler/0">handler</a>())}
| {:fallback, (<a href="https://hexdocs.pm/elixir/String.html#t:t/0">String.t</a>(), <a href="https://hexdocs.pm/elixir/typespecs.html#built-in-types">list</a>() -&gt; <a href="https://hexdocs.pm/elixir/typespecs.html#built-in-types">term</a>())}</pre>
</div>
</section>
</section>
</div>
</section>
<section id="functions" class="details-list">
<h2 class="section-heading">
<a class="hover-link" href="#functions">
<i class="ri-link-m" aria-hidden="true"></i>
</a>
<span class="text">Functions</span>
</h2>
<div class="functions-list">
<section class="detail" id="child_spec/1">
<div class="detail-header">
<a href="#child_spec/1" class="detail-link" data-no-tooltip="" aria-label="Link to this function">
<i class="ri-link-m" aria-hidden="true"></i>
</a>
<div class="heading-with-actions">
<h1 class="signature" translate="no">child_spec(init_arg)</h1>
</div>
</div>
<section class="docstring">
<p>Returns a specification to start this module under a supervisor.</p><p>See <a href="https://hexdocs.pm/elixir/Supervisor.html"><code class="inline">Supervisor</code></a>.</p>
</section>
</section>
<section class="detail" id="start_link/1">
<span id="start_link/0"></span>
<div class="detail-header">
<a href="#start_link/1" class="detail-link" data-no-tooltip="" aria-label="Link to this function">
<i class="ri-link-m" aria-hidden="true"></i>
</a>
<div class="heading-with-actions">
<h1 class="signature" translate="no">start_link(opts \\ [])</h1>
</div>
</div>
<section class="docstring">
<div class="specs">
<pre translate="no"><span class="attribute">@spec</span> start_link([<a href="#t:start_option/0">start_option</a>()]) :: <a href="https://hexdocs.pm/elixir/GenServer.html#t:on_start/0">GenServer.on_start</a>()</pre>
</div>
<p>Starts a dispatcher process.</p><p>Most callers should let <a href="Boam.Runtime.html"><code class="inline">Boam.Runtime</code></a> create a dispatcher
automatically. Start this module directly when you want to reuse a single
dispatch process across several runtimes or supervise it yourself.</p>
</section>
</section>
</div>
</section>
<footer class="footer">
<p>
<span class="line">
<a href="https://hex.pm/packages/boam/0.1.3">Hex Package</a>
<a href="https://preview.hex.pm/preview/boam/0.1.3">Hex Preview</a>
</span>
<span class="line">
<button class="a-main footer-button display-quick-switch" title="Go to package docs">
Go to package docs
</button>
<a href="llms.txt" target="_blank">
View llms.txt
</a>
<a href="boam.epub">
Download ePub version
</a>
</span>
</p>
<p class="built-using">
Built using
<a href="https://github.com/elixir-lang/ex_doc" title="ExDoc" target="_blank" rel="help noopener" translate="no">ExDoc</a> (v0.40.1) for the
<a href="https://elixir-lang.org" title="Elixir" target="_blank" translate="no">Elixir programming language</a>
</p>
</footer>
</div>
</main>
</div>
</body>
</html>