TheaterRuntime

Struct TheaterRuntime 

Source
pub struct TheaterRuntime {
    pub theater_tx: Sender<TheaterCommand>,
    /* private fields */
}
Expand description

§TheaterRuntime

The central runtime for the Theater actor system, responsible for managing actors and their lifecycles.

§Purpose

TheaterRuntime is the core component that coordinates actors within the Theater system. It handles actor creation, destruction, communication, and provides the foundation for the actor supervision system. The runtime also manages channels for communication between actors and external systems.

§Example

use theater::theater_runtime::TheaterRuntime;
use theater::messages::TheaterCommand;
use tokio::sync::mpsc;
use anyhow::Result;

async fn example() -> Result<()> {
    // Create channels for theater commands
    let (theater_tx, theater_rx) = mpsc::channel(100);
     
    // Initialize the runtime
    let mut runtime = TheaterRuntime::new(theater_tx.clone(), theater_rx, None, Default::default()).await?;
     
    // Start a background task to run the runtime
    let runtime_handle = tokio::spawn(async move {
        runtime.run().await
    });
     
    // Use the theater_tx to send commands to the runtime
    // ...
     
    Ok(())
}

§Safety

TheaterRuntime provides a safe interface to the WebAssembly actors. All potentially unsafe operations involving WebAssembly execution are handled in the ActorRuntime and ActorExecutor components with appropriate checks and validations.

§Security

TheaterRuntime enforces sandbox boundaries for actors, preventing unauthorized access to system resources. Each actor runs in an isolated WebAssembly environment with controlled capabilities defined in its manifest.

§Implementation Notes

The runtime uses a command-based architecture where all operations are sent as messages through channels. This allows for asynchronous processing and helps maintain isolation between components.

Fields§

§theater_tx: Sender<TheaterCommand>

Sender for commands to the runtime

Implementations§

Source§

impl TheaterRuntime

Source

pub async fn new( theater_tx: Sender<TheaterCommand>, theater_rx: Receiver<TheaterCommand>, channel_events_tx: Option<Sender<ChannelEvent>>, permissions: HandlerPermission, ) -> Result<Self>

Creates a new TheaterRuntime with the given communication channels.

§Parameters
  • theater_tx - Sender for commands to the runtime
  • theater_rx - Receiver for commands to the runtime
  • channel_events_tx - Optional channel for sending events to external systems
§Returns

A new TheaterRuntime instance ready to be started.

§Example
let (theater_tx, theater_rx) = mpsc::channel::<TheaterCommand>(100);
let runtime = TheaterRuntime::new(theater_tx, theater_rx, None, Default::default()).await?;
Source

pub async fn run(&mut self) -> Result<()>

Starts the runtime’s main event loop, processing commands until shutdown.

§Purpose

This method runs the main event loop of the runtime, processing commands from the theater_rx channel and dispatching them to the appropriate handlers. It will continue running until the channel is closed or an error occurs.

§Returns
  • Ok(()) - The runtime has shut down gracefully
  • Err(anyhow::Error) - An error occurred during runtime execution
§Implementation Notes

This method is typically run in a separate task and should be considered the main execution context for the runtime. It handles all commands asynchronously and manages actor lifecycles.

Source

pub async fn get_channel_status( &self, channel_id: &ChannelId, ) -> Option<Vec<ChannelParticipant>>

Source

pub async fn list_channels(&self) -> Vec<(ChannelId, Vec<ChannelParticipant>)>

Source

pub async fn stop(&mut self) -> Result<()>

Stops the entire runtime and all actors gracefully.

§Returns
  • Ok(()) - The runtime was successfully stopped
  • Err(anyhow::Error) - An error occurred during the stop process
§Example
// Shut down the runtime
runtime.stop().await?;
§Implementation Notes

This method stops all actors managed by the runtime and cleans up any resources.

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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 = 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.
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
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,