Runtime

Struct Runtime 

Source
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

Source

pub fn new(placed: Placed, backend: Arc<dyn Backend>) -> Result<Runtime>

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.

Source

pub fn backend(&self) -> &'static str

Which backend prepared this program — for a diagnostic, and for the report that says two backends disagreed.

Source

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.

Source

pub fn placed(&self) -> &Placed

Source

pub fn wire_id(&self) -> &str

Source

pub fn initial_state(&self) -> Result<Value>

Source

pub fn proposal(&self, actor: &(impl Viewer + ?Sized), command: Value) -> Value

Build the Proposal record the program’s validate expects.

Source

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.

Source

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.

Source

pub fn fold(&self, state: &Value, env: &Envelope, event: Value) -> Result<Value>

The replay-pure fold. env supplies seq, at and actor as data (§3.7).

Source

pub fn view( &self, state: &Value, actor: &(impl Viewer + ?Sized), ) -> Result<Html>

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.

Source

pub fn contribution(&self, actor: &(impl Viewer + ?Sized)) -> Result<Value>

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.

Source

pub fn contribution_of( &self, actor: &(impl Viewer + ?Sized), ) -> Result<Option<Value>>

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.

Source

pub fn view_with( &self, state: &Value, actor: &(impl Viewer + ?Sized), here: &Value, ) -> Result<Html>

The same view, against a roster somebody else is keeping (crate::presence).

Source

pub fn view_with_all( &self, state: &Value, actor: &(impl Viewer + ?Sized), here: &Value, aware: &Value, ) -> Result<Html>

The view, against both rosters a caller may be keeping.

Source

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.

Source

pub fn plan(&self) -> &Arc<Plan>

The view as a dataflow plan — what beck explain incremental reports on.

Source

pub fn view_engine(&self) -> Result<Engine>

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.

Source

pub fn shared_dataflow(&self, retention: Retention) -> Arc<SharedDataflow>

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.

Source

pub fn render( &self, engine: &mut Engine, state: &Value, actor: &(impl Viewer + ?Sized), here: &Value, aware: &Value, ) -> Result<Html>

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.

Source

pub fn render_shared( &self, shared: &SharedDataflow, engine: &mut Engine, state: &Value, version: u64, actor: &(impl Viewer + ?Sized), here: &Value, aware: &Value, ) -> Result<(Html, u64)>

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.

Source

pub fn prepare(&self, code: &Core) -> Result<Callable>

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.

Source

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.

Source

pub fn decode_command(&self, json: &Value) -> Result<Value>

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]).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.