Skip to main content

RuntimeHandle

Struct RuntimeHandle 

Source
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

Source

pub fn plan(&self) -> RuntimePlan

The capability plan this runtime was started with.

Source

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.

Source

pub fn client_count(&self) -> usize

Number of WebSocket clients currently connected to this runtime.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more