pub struct LiveHub { /* private fields */ }Expand description
Holds the lowered app and its open connections; turns publish
into targeted re-renders. With a live_handler set the re-render
is a structural diff (design.md §10, A3); otherwise it is the
broadcast-refresh full page (A1).
Implementations§
Source§impl LiveHub
impl LiveHub
pub fn new(wasm: Vec<u8>, handler: &str, db_path: &str) -> Self
Sourcepub fn set_live_handler(&mut self, name: &str)
pub fn set_live_handler(&mut self, name: &str)
Opt this hub into diff-based push (design.md §10, A3): name is
the app’s <handler>_live entry (the run_app_live envelope —
full HTML on first render, the Change wire thereafter). Without
this the hub stays broadcast-refresh (A1), unchanged.
Sourcepub fn connect(
&mut self,
topics: Vec<String>,
method: &str,
path: &str,
body: &str,
) -> Result<(u64, HttpResponse), RunError>
pub fn connect( &mut self, topics: Vec<String>, method: &str, path: &str, body: &str, ) -> Result<(u64, HttpResponse), RunError>
Open a connection for a page request. Returns its id and the
initial rendered response. topics is what this page subscribes
to. Any publishes during the initial render are discarded — a
fresh page is its own latest state.
Sourcepub fn connect_subscribed(
&mut self,
subs_handler: &str,
method: &str,
path: &str,
body: &str,
) -> Result<(u64, HttpResponse), RunError>
pub fn connect_subscribed( &mut self, subs_handler: &str, method: &str, path: &str, body: &str, ) -> Result<(u64, HttpResponse), RunError>
Like connect but the page’s topics come from
the app itself: a subscriptions(req) -> Response handler whose
body is the whitespace-delimited topic list (the v1 ABI form of
design.md §10’s subscriptions: Fn(Model) -> List<Topic> —
pure, explicit, reviewed, no magic dependency capture). An empty
body means the page subscribes to nothing.
Sourcepub fn request(
&self,
method: &str,
path: &str,
body: &str,
) -> Result<HttpResponse, RunError>
pub fn request( &self, method: &str, path: &str, body: &str, ) -> Result<HttpResponse, RunError>
A one-shot request that is not itself a live connection (e.g. the
POST that mutates state and publishes). Publishes it performs
are queued on this thread for the next drain_and_push.
Sourcepub fn drain_and_push(&mut self) -> Result<Vec<(u64, HttpResponse)>, RunError>
pub fn drain_and_push(&mut self) -> Result<Vec<(u64, HttpResponse)>, RunError>
Drain the topics published on this thread since the last call;
for every connection subscribed to any of them, re-render
(stateless: the same request against the new DB state) and
return (conn_id, fresh response) to write down its socket.
Unsubscribed connections are untouched.
Sourcepub fn disconnect(&mut self, id: u64)
pub fn disconnect(&mut self, id: u64)
Drop a connection by id — called when its socket write fails
(the client went away). After this the connection is no longer
re-rendered by drain_and_push. Unknown ids are a no-op (an
already-pruned conn double-reported as dead is not an error).
Sourcepub fn connections(&self) -> usize
pub fn connections(&self) -> usize
Open connection count (for observability/tests).
Auto Trait Implementations§
impl Freeze for LiveHub
impl RefUnwindSafe for LiveHub
impl Send for LiveHub
impl Sync for LiveHub
impl Unpin for LiveHub
impl UnsafeUnpin for LiveHub
impl UnwindSafe for LiveHub
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more