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
impl TheaterRuntime
Sourcepub async fn new(
theater_tx: Sender<TheaterCommand>,
theater_rx: Receiver<TheaterCommand>,
channel_events_tx: Option<Sender<ChannelEvent>>,
permissions: HandlerPermission,
) -> Result<Self>
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 runtimetheater_rx- Receiver for commands to the runtimechannel_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?;Sourcepub async fn run(&mut self) -> Result<()>
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 gracefullyErr(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.
pub async fn get_channel_status( &self, channel_id: &ChannelId, ) -> Option<Vec<ChannelParticipant>>
pub async fn list_channels(&self) -> Vec<(ChannelId, Vec<ChannelParticipant>)>
Sourcepub async fn stop(&mut self) -> Result<()>
pub async fn stop(&mut self) -> Result<()>
Stops the entire runtime and all actors gracefully.
§Returns
Ok(())- The runtime was successfully stoppedErr(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§
impl Freeze for TheaterRuntime
impl !RefUnwindSafe for TheaterRuntime
impl Send for TheaterRuntime
impl Sync for TheaterRuntime
impl Unpin for TheaterRuntime
impl !UnwindSafe for TheaterRuntime
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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