Skip to main content

ChannelRunner

Struct ChannelRunner 

Source
pub struct ChannelRunner { /* private fields */ }
Expand description

Execution context for a single Channel.

ChannelRunner provides the runtime environment for parallel channel execution. Each runner:

  • Binds 1:1 with a Component
  • Receives Events via an mpsc channel and delivers to Component
  • Receives Signals via broadcast and delivers to Component
  • Sends World modifications via command queue
  • Has read access to the World for queries
  • Manages spawned children via ChildSpawner

Implementations§

Source§

impl ChannelRunner

Source

pub fn hook_registry(&self) -> Option<&SharedHookRegistry>

Returns a reference to the shared hook registry, if configured.

Source

pub fn create_child_context( &self, child_id: &str, ) -> Option<Box<dyn ChildContext>>

Creates a ChildContext for use by managed children.

The returned context can be injected into LuaChild instances to enable them to spawn sub-children.

Returns None if child spawning was not enabled for this runner.

Source

pub fn create_child_context_with_loader( &self, child_id: &str, loader: Arc<dyn LuaChildLoader>, ) -> Option<Box<dyn ChildContext>>

Creates a ChildContext with a LuaChildLoader for spawning Lua children.

§Arguments
  • child_id - ID of the child that will use this context
  • loader - Loader for creating LuaChild instances from configs
Source

pub fn create_async_child_context( &self, child_id: &str, ) -> Option<Box<dyn AsyncChildContext>>

Creates an AsyncChildContext for use by async children.

The returned context can be used with async spawn operations.

Returns None if child spawning was not enabled for this runner.

Source

pub fn create_async_child_context_with_loader( &self, child_id: &str, loader: Arc<dyn LuaChildLoader>, ) -> Option<Box<dyn AsyncChildContext>>

Creates an AsyncChildContext with a LuaChildLoader.

§Arguments
  • child_id - ID of the child that will use this context
  • loader - Loader for creating LuaChild instances from configs
Source

pub fn child_spawner(&self) -> Option<&Arc<StdMutex<ChildSpawner>>>

Returns a reference to the child spawner, if enabled.

Source

pub fn id(&self) -> ChannelId

Returns this channel’s ID.

Source

pub fn world_tx(&self) -> &Sender<WorldCommand>

Returns a reference to the world_tx sender.

Source

pub fn world(&self) -> &Arc<RwLock<World>>

Returns a reference to the world.

Source

pub async fn run(self) -> RunnerResult

Runs the channel’s event loop.

This method consumes the runner and processes events until:

  • The channel is completed or killed
  • A Veto signal is received
  • All event senders are dropped

After the event loop exits, executes the shutdown sequence:

  1. Capture component snapshot (if supported)
  2. Call component.shutdown() for cleanup
  3. Return RunnerResult with snapshot

If an initial snapshot was provided via ChannelRunnerBuilder::with_initial_snapshot(), it is restored before init() is called.

Source

pub async fn spawn_child( &self, config: ChannelConfig, signal_rx: Receiver<Signal>, component: Box<dyn Component>, ) -> Option<(ChannelRunner, ChannelHandle)>

Spawns a child channel with a bound Component.

Returns the new channel’s ID and handle, or None if spawn failed.

Source§

impl ChannelRunner

Source

pub fn builder( id: ChannelId, world_tx: Sender<WorldCommand>, world: Arc<RwLock<World>>, signal_rx: Receiver<Signal>, component: Box<dyn Component>, ) -> ChannelRunnerBuilder

Creates a new builder for constructing a ChannelRunner.

This is the recommended way to create runners with optional features.

§Example
let (runner, handle) = ChannelRunner::builder(id, world_tx, world, signal_rx, component)
    .with_emitter(signal_tx)
    .with_child_spawner(None)
    .build();

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, 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<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