pub struct Runtime { /* private fields */ }Expand description
The compiled program plus the capabilities the host holds on its behalf.
Note what is absent: any mention of how the program executes. The roles are [Callable]s a
[Backend] prepared, so a native backend is a different argument to Runtime::new rather
than a change here — and §4.8’s differential test between backends is two Runtimes over the
same Placed.
Implementations§
Source§impl Runtime
impl Runtime
Sourcepub fn new(placed: Placed, backend: Arc<dyn Backend>) -> Result<Runtime, Error>
pub fn new(placed: Placed, backend: Arc<dyn Backend>) -> Result<Runtime, Error>
Prepare a program for execution by a given backend.
The backend is an argument rather than a default because a default is how beck-rt ends up
naming one implementation again. This crate does not depend on any backend crate, and that
is the property worth keeping.
Sourcepub fn backend(&self) -> &'static str
pub fn backend(&self) -> &'static str
Which backend prepared this program — for a diagnostic, and for the report that says two backends disagreed.
Sourcepub fn executor(&self) -> &dyn Backend
pub fn executor(&self) -> &dyn Backend
The backend itself, for whoever has to prepare something this runtime did not.
The read model’s relational SQL is the caller: a join, a group by and a distinct are
compiled into a plan at query time and a plan is prepared by a backend
(docs/99 §99.9 item 9). It
is the same backend the program runs on, which is the property that matters — a query and
the page it is a view of are executed by one implementation.
pub fn placed(&self) -> &Placed
pub fn wire_id(&self) -> &str
pub fn initial_state(&self) -> Result<Value, Error>
Sourcepub fn proposal(&self, actor: &(impl Viewer + ?Sized), command: Value) -> Value
pub fn proposal(&self, actor: &(impl Viewer + ?Sized), command: Value) -> Value
Build the Proposal record the program’s validate expects.
Sourcepub fn decide(&self, state: &Value, proposal: &Value) -> Result<Value, String>
pub fn decide(&self, state: &Value, proposal: &Value) -> Result<Value, String>
The authority chokepoint, as the program wrote it: the whole
Result[list[Event], Rejection].
Runtime::validate narrows this to “events, or a message”, which is what an ingress
handler needs and what a test cannot use: §21.2’s expect Err(BlankText) is an assertion
about the rejection value, and rendering it to a string first would make the assertion a
string comparison.
Sourcepub fn validate(
&self,
state: &Value,
proposal: &Value,
) -> Result<Vec<Value>, String>
pub fn validate( &self, state: &Value, proposal: &Value, ) -> Result<Vec<Value>, String>
The authority chokepoint. Returns the events a proposal becomes, or why it was refused.
Sourcepub fn fold(
&self,
state: &Value,
env: &Envelope,
event: Value,
) -> Result<Value, Error>
pub fn fold( &self, state: &Value, env: &Envelope, event: Value, ) -> Result<Value, Error>
The replay-pure fold. env supplies seq, at and actor as data (§3.7).
Sourcepub fn view(
&self,
state: &Value,
actor: &(impl Viewer + ?Sized),
) -> Result<Html, Error>
pub fn view( &self, state: &Value, actor: &(impl Viewer + ?Sized), ) -> Result<Html, Error>
The per-session view. In Mode A this runs server-side and its output is diffed (§5.1).
The roster it renders against is the viewer’s own — edge::presence_of — because a caller
with no connection registry is rendering the page one actor sees while looking at it.
Runtime::view_with is what an application uses, and it is the same function.
Sourcepub fn contribution(
&self,
actor: &(impl Viewer + ?Sized),
) -> Result<Value, Error>
pub fn contribution( &self, actor: &(impl Viewer + ?Sized), ) -> Result<Value, Error>
This client’s own awareness contribution, or an empty roster when the page reads none.
The one-connection case, and it is Runtime::view’s reason: a caller with no registry is
rendering the page one actor sees while looking at it, so the roster contains them and
nobody else.
Sourcepub fn contribution_of(
&self,
actor: &(impl Viewer + ?Sized),
) -> Result<Option<Value>, Error>
pub fn contribution_of( &self, actor: &(impl Viewer + ?Sized), ) -> Result<Option<Value>, Error>
What this client contributes to everybody else’s roster, or None when the page reads no
awareness.
The bare value rather than a roster of one, because the caller that matters is a registry
holding one of these per connection (beck_rt::awareness), and it keys them itself. None
rather than Unit so that a program which reads no awareness costs a registry nothing —
there is a difference between contributing nothing and having nothing to contribute.
Sourcepub fn view_with(
&self,
state: &Value,
actor: &(impl Viewer + ?Sized),
here: &Value,
) -> Result<Html, Error>
pub fn view_with( &self, state: &Value, actor: &(impl Viewer + ?Sized), here: &Value, ) -> Result<Html, Error>
The same view, against a roster somebody else is keeping (crate::presence).
Sourcepub fn view_with_all(
&self,
state: &Value,
actor: &(impl Viewer + ?Sized),
here: &Value,
aware: &Value,
) -> Result<Html, Error>
pub fn view_with_all( &self, state: &Value, actor: &(impl Viewer + ?Sized), here: &Value, aware: &Value, ) -> Result<Html, Error>
The view, against both rosters a caller may be keeping.
Sourcepub fn gestures_init(&self) -> &Value
pub fn gestures_init(&self) -> &Value
The accumulator a client starts an interface with — D30’s gestures(step, init)’s init.
Unit when the program keeps no interface state.
Sourcepub fn plan(&self) -> &Arc<Plan>
pub fn plan(&self) -> &Arc<Plan>
The view as a dataflow plan — what beck explain incremental reports on.
Sourcepub fn view_engine(&self) -> Result<Engine, Error>
pub fn view_engine(&self) -> Result<Engine, Error>
A maintained view for one subscriber, computing the whole plan itself.
One per subscription, because §3.8’s per-session views are “the norm, not the exception” and
an arrangement below a per_session is that subscriber’s. Everything above it is the same
computation for everybody — [Plan::shared] says which nodes — and this engine holds a copy
of it. Runtime::shared_dataflow is the one that does not.
The shared half of the plan — §5.3’s “one shared dataflow” — for a process to hold one of.
It is created per application rather than per Runtime because what it holds is derived
from the accumulator, and the accumulator belongs to the application. A Runtime with no
application driving it (beck test, the differential harness) never makes one.
retention says how long it keeps what a subscriber might still ask for, and comes from the
application’s configuration for the reason beck_rt::AppConfig::retention gives.
Sourcepub fn render(
&self,
engine: &mut Engine,
state: &Value,
actor: &(impl Viewer + ?Sized),
here: &Value,
aware: &Value,
) -> Result<Html, Error>
pub fn render( &self, engine: &mut Engine, state: &Value, actor: &(impl Viewer + ?Sized), here: &Value, aware: &Value, ) -> Result<Html, Error>
Render a subscriber’s view by maintaining it, rather than by recomputing it.
Identical output to Runtime::view — beck-cli/tests/incremental_engine.rs is the gate,
over every corpus program and every event of a generated log.
The same maintained render, with the operators that do not read the session taken from a dataflow shared with every other subscriber (§5.3).
Returns the version the page reflects, which may be newer than version: another subscriber
may have advanced the shared side first, and a page of the newer state is right where
unwinding an arrangement back to the older one is not.
Sourcepub fn prepare(
&self,
code: &Core,
) -> Result<Arc<dyn Fn(Vec<Value>) -> Result<Value, ExecError> + Sync + Send>, Error>
pub fn prepare( &self, code: &Core, ) -> Result<Arc<dyn Fn(Vec<Value>) -> Result<Value, ExecError> + Sync + Send>, Error>
Prepare an arbitrary Core lambda for calling, through the same backend the roles use.
The one caller is the test runner (§21.2), which has to evaluate an expect expression with
state, events and result bound. It goes through [Backend::function] rather than
reaching into an evaluator, so a compiling backend serves it unchanged.
Sourcepub fn session(&self, actor: &(impl Viewer + ?Sized)) -> Value
pub fn session(&self, actor: &(impl Viewer + ?Sized)) -> Value
The Session value a subscriber’s view is rendered against.
Public because the incremental view engine takes it as an input rather than receiving it
through Runtime::view: a plan’s session is a node, and everything not downstream of it
is what §5.3 shares between subscribers.
Sourcepub fn decode_command(&self, json: &Value) -> Result<Value, Error>
pub fn decode_command(&self, json: &Value) -> Result<Value, Error>
Decode a command from the wire, against the program’s own Command union.
The union is resolved to a [beck_core::command::Schema] once, at compile time, and both
tiers decode with it: Mode B’s client holds a bundle rather than a program, and a second
decoder written against a second reading of the same union is the failure mode that is
worth designing out ([beck_core::command]).