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
Principalfor 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
impl BaseChannel
Sourcepub fn new(
id: ChannelId,
parent: Option<ChannelId>,
config: ChannelConfig,
principal: Principal,
) -> Self
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 channelparent- Parent channel ID, orNonefor root channelsconfig- Configuration controlling channel behaviorprincipal- 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);Sourcepub fn new_with_ancestors(
id: ChannelId,
parent: ChannelId,
config: ChannelConfig,
principal: Principal,
ancestor_path: Vec<ChannelId>,
) -> Self
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 channelparent- Parent channel IDconfig- Configuration controlling channel behaviorprincipal- Principal for scope resolutionancestor_path- Pre-computed path: [parent, grandparent, …, root]
Trait Implementations§
Source§impl ChannelCore for BaseChannel
impl ChannelCore for BaseChannel
Source§fn principal(&self) -> &Principal
fn principal(&self) -> &Principal
Returns the principal associated with this channel. Read more
Source§fn state(&self) -> &ChannelState
fn state(&self) -> &ChannelState
Returns a reference to the current state.
Source§fn config(&self) -> &ChannelConfig
fn config(&self) -> &ChannelConfig
Returns a reference to the channel’s configuration.
Source§fn children(&self) -> &HashSet<ChannelId>
fn children(&self) -> &HashSet<ChannelId>
Returns a reference to the set of child channel IDs.
Source§fn ancestor_path(&self) -> &[ChannelId]
fn ancestor_path(&self) -> &[ChannelId]
Returns the cached ancestor path. Read more
Source§fn is_running(&self) -> bool
fn is_running(&self) -> bool
Returns
true if the channel is in Running state.Source§fn is_awaiting_approval(&self) -> bool
fn is_awaiting_approval(&self) -> bool
Returns
true if the channel is in AwaitingApproval state.Source§fn is_terminal(&self) -> bool
fn is_terminal(&self) -> bool
Returns
true if the channel is in a terminal state (Completed or Aborted).Source§fn has_children(&self) -> bool
fn has_children(&self) -> bool
Returns
true if this channel has any children.Source§fn is_descendant_of(&self, ancestor: ChannelId) -> bool
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
impl ChannelMut for BaseChannel
Source§fn await_approval(&mut self, request_id: String) -> bool
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>
fn resolve_approval(&mut self, approval_id: &str) -> Option<String>
Resolves approval and transitions to Running state. Read more
Source§fn remove_child(&mut self, id: &ChannelId)
fn remove_child(&mut self, id: &ChannelId)
Unregisters a child channel.
Auto Trait Implementations§
impl Freeze for BaseChannel
impl RefUnwindSafe for BaseChannel
impl Send for BaseChannel
impl Sync for BaseChannel
impl Unpin for BaseChannel
impl UnsafeUnpin for BaseChannel
impl UnwindSafe for BaseChannel
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
Mutably borrows from an owned value. Read more