pub struct RuntimeHandle { /* private fields */ }Expand description
A running Runtime, owned by whoever called Runtime::spawn.
Dropping the handle does not stop the runtime; the tasks it owns keep
running on the tokio runtime. Call shutdown to stop
them and release the memory they hold. This is deliberate: the same
semantics as dropping a JoinHandle, and what lets run hand the handle
across a select!.
Implementations§
Source§impl RuntimeHandle
impl RuntimeHandle
Sourcepub fn plan(&self) -> RuntimePlan
pub fn plan(&self) -> RuntimePlan
The capability plan this runtime was started with.
Sourcepub async fn is_ready(&self) -> bool
pub async fn is_ready(&self) -> bool
Whether this runtime should take traffic: the stream is healthy and,
after a snapshot restore, the parser has caught back up to the slot
tip. The same test the HTTP /ready endpoint applies.
Sourcepub fn client_count(&self) -> usize
pub fn client_count(&self) -> usize
Number of WebSocket clients currently connected to this runtime.
Sourcepub async fn entity_cache_stats(&self) -> Option<CacheStats>
pub async fn entity_cache_stats(&self) -> Option<CacheStats>
What this runtime’s entity cache holds: the entities kept per view
for snapshot-on-subscribe. For an embedder accounting for the
runtime’s memory. None when the runtime has no live runtime.
Sourcepub async fn serve_connection(
&self,
stream: TcpStream,
remote_addr: SocketAddr,
) -> Result<()>
pub async fn serve_connection( &self, stream: TcpStream, remote_addr: SocketAddr, ) -> Result<()>
Serve a TCP connection the caller accepted, as this runtime’s WebSocket server would have: handshake, authentication, then the subscription session until the peer disconnects.
Resolves when the session ends, or when the runtime shuts down. Fails
if the runtime has no live runtime (no buses to subscribe to). Callers
that serve from an accept loop should take a
connection_server, which is cheap to clone
into each connection’s task.
Sourcepub fn connection_server(&self) -> Option<ConnectionServer>
pub fn connection_server(&self) -> Option<ConnectionServer>
A clonable handle that serves connections against this runtime.
None when the runtime has no live runtime. Sessions served through a
clone are ended by shutdown like any other.
Sourcepub async fn exited(&mut self)
pub async fn exited(&mut self)
Resolves when a core task - projector, parser or WebSocket listener -
exits on its own. run treats that as a reason to shut down.
Sourcepub async fn shutdown(self) -> Result<()>
pub async fn shutdown(self) -> Result<()>
Stop the runtime: take the final snapshot if configured, stop producing, let the projector drain, close sessions, then stop everything else.
Order matters. The final snapshot is taken first, while the parser is still running: capture takes the barrier exclusively, so it waits for every in-flight update to reach the projector and records one consistent cut. Aborting the parser before that could cut an update between its VM write and its batch, and the snapshot would keep the write without the projection. Only then is the parser aborted; anything it produces after the snapshot is simply not restored. The sender is dropped so the projector exits once its queue is empty, bounded by a timeout after which it is aborted and awaited. Sessions are ended through their normal cleanup, the HTTP health server is signalled and its thread joined, and the remaining tasks are aborted.