Boam.Dispatcher
(boam v0.1.2)
Copy Markdown
Dispatch process for beam.call(...) requests originating in JavaScript.
A dispatcher is an ordinary GenServer that receives messages from the Rust
runtime, resolves the requested handler, executes it on the BEAM, and replies
back to the waiting JavaScript call.
In the default setup you do not need to start this module manually;
Boam.Runtime starts one automatically when no explicit
:dispatcher pid is supplied.
Handler Forms
Handlers can be provided in three shapes:
fn args -> result endfn name, args -> result end{Module, :function}which is called asapply(Module, :function, [args])
Return Contract
A handler may return:
- any JSON-compatible value, which becomes the JavaScript return value
{:ok, value}, which unwraps tovalue{:error, reason}, which raises a JavaScript error
If a handler crashes, the formatted exception is sent back as a JavaScript error message instead of leaving the runtime hanging.
Summary
Types
Function or MFA that can satisfy a beam.call(...) request.
Functions
Returns a specification to start this module under a supervisor.
Starts a dispatcher process.
Types
Function or MFA that can satisfy a beam.call(...) request.
@type start_option() :: {:name, GenServer.name()} | {:exports, %{optional(export_name()) => handler()} | keyword(handler())} | {:fallback, (String.t(), list() -> term())}
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec start_link([start_option()]) :: GenServer.on_start()
Starts a dispatcher process.
Most callers should let Boam.Runtime create a dispatcher
automatically. Start this module directly when you want to reuse a single
dispatch process across several runtimes or supervise it yourself.