Skip to main content

BaseChannel

Struct BaseChannel 

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

Base channel implementation.

A BaseChannel represents an isolated execution context that can:

  • Track its current state (ChannelState)
  • Maintain parent-child relationships
  • Control behavior via ChannelConfig
  • Transition through its lifecycle
  • Hold a Principal for scope resolution

§Parent-Child Relationships

Channels form a tree structure:

  • Primary channel has no parent (parent() == None)
  • Child channels reference their parent
  • A channel tracks all its children

§Ancestor Path (DOD Optimization)

Each channel maintains a cached path to all ancestors for O(1) descendant checks. The path is ordered from immediate parent to root: [parent, grandparent, ..., root].

§Configuration

Channel behavior is controlled by ChannelConfig:

  • priority: Determines scheduling order (0-255, higher = more priority)
  • can_spawn: Whether this channel can create children

§Example

use orcs_runtime::{BaseChannel, ChannelConfig, ChannelCore, ChannelMut, ChannelState};
use orcs_types::{ChannelId, Principal};

// Create a root channel
let root_id = ChannelId::new();
let mut root = BaseChannel::new(root_id, None, ChannelConfig::interactive(), Principal::System);
assert_eq!(root.priority(), 255);
assert!(root.can_spawn());

// Create a background child channel
let child_id = ChannelId::new();
let child = BaseChannel::new(child_id, Some(root_id), ChannelConfig::background(), Principal::System);
assert_eq!(child.priority(), 10);
assert!(!child.can_spawn());

root.add_child(child_id);
assert!(root.has_children());

Implementations§

Source§

impl BaseChannel

Source

pub fn new( id: ChannelId, parent: Option<ChannelId>, config: ChannelConfig, principal: Principal, ) -> Self

Creates a new channel in Running state.

§Arguments
  • id - Unique identifier for this channel
  • parent - Parent channel ID, or None for root channels
  • config - Configuration controlling channel behavior
  • principal - Principal for scope resolution
§Note

The ancestor_path is initialized empty. When spawning via World, use new_with_ancestors to properly set the ancestor path.

§Example
use orcs_runtime::{BaseChannel, ChannelConfig, ChannelCore};
use orcs_types::{ChannelId, Principal};

// Primary channel (no parent, highest priority)
let root = BaseChannel::new(ChannelId::new(), None, ChannelConfig::interactive(), Principal::System);
assert_eq!(root.priority(), 255);

// Background child channel
let parent_id = ChannelId::new();
let child = BaseChannel::new(ChannelId::new(), Some(parent_id), ChannelConfig::background(), Principal::System);
assert_eq!(child.priority(), 10);
Source

pub fn new_with_ancestors( id: ChannelId, parent: ChannelId, config: ChannelConfig, principal: Principal, ancestor_path: Vec<ChannelId>, ) -> Self

Creates a new channel with a pre-computed ancestor path.

This constructor is used by World when spawning child channels to maintain the ancestor path for O(1) descendant checks.

§Arguments
  • id - Unique identifier for this channel
  • parent - Parent channel ID
  • config - Configuration controlling channel behavior
  • principal - Principal for scope resolution
  • ancestor_path - Pre-computed path: [parent, grandparent, …, root]

Trait Implementations§

Source§

impl ChannelCore for BaseChannel

Source§

fn id(&self) -> ChannelId

Returns the channel’s unique identifier.
Source§

fn principal(&self) -> &Principal

Returns the principal associated with this channel. Read more
Source§

fn state(&self) -> &ChannelState

Returns a reference to the current state.
Source§

fn config(&self) -> &ChannelConfig

Returns a reference to the channel’s configuration.
Source§

fn parent(&self) -> Option<ChannelId>

Returns the parent channel’s ID, if any.
Source§

fn children(&self) -> &HashSet<ChannelId>

Returns a reference to the set of child channel IDs.
Source§

fn ancestor_path(&self) -> &[ChannelId]

Returns the cached ancestor path. Read more
Source§

fn is_running(&self) -> bool

Returns true if the channel is in Running state.
Source§

fn is_paused(&self) -> bool

Returns true if the channel is in Paused state.
Source§

fn is_awaiting_approval(&self) -> bool

Returns true if the channel is in AwaitingApproval state.
Source§

fn is_terminal(&self) -> bool

Returns true if the channel is in a terminal state (Completed or Aborted).
Source§

fn priority(&self) -> u8

Returns the scheduling priority (0-255).
Source§

fn can_spawn(&self) -> bool

Returns whether this channel can spawn children.
Source§

fn has_children(&self) -> bool

Returns true if this channel has any children.
Source§

fn depth(&self) -> usize

Returns the depth of this channel in the tree.
Source§

fn is_descendant_of(&self, ancestor: ChannelId) -> bool

Returns true if this channel is a descendant of the given ancestor.
Source§

impl ChannelMut for BaseChannel

Source§

fn complete(&mut self) -> bool

Transitions to Completed state. Read more
Source§

fn abort(&mut self, reason: String) -> bool

Transitions to Aborted state. Read more
Source§

fn pause(&mut self) -> bool

Transitions to Paused state. Read more
Source§

fn resume(&mut self) -> bool

Transitions from Paused to Running state. Read more
Source§

fn await_approval(&mut self, request_id: String) -> bool

Transitions to AwaitingApproval state. Read more
Source§

fn resolve_approval(&mut self, approval_id: &str) -> Option<String>

Resolves approval and transitions to Running state. Read more
Source§

fn add_child(&mut self, id: ChannelId)

Registers a child channel.
Source§

fn remove_child(&mut self, id: &ChannelId)

Unregisters a child channel.
Source§

impl Debug for BaseChannel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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