pub struct ThreadRuntime {
pub thread: RwLock<Thread>,
pub interactions: RwLock<HashMap<InteractionId, Interaction>>,
pub concurrency_policy: Arc<dyn ConcurrencyPolicy>,
pub event_store: Arc<dyn EventStore>,
pub event_bus: Arc<dyn EventBus>,
pub config: ThreadRuntimeConfig,
}Expand description
ThreadRuntime - manages thread lifecycle and interaction concurrency
Fields§
§thread: RwLock<Thread>The thread being managed
interactions: RwLock<HashMap<InteractionId, Interaction>>Active interactions in this thread
concurrency_policy: Arc<dyn ConcurrencyPolicy>Concurrency policy
event_store: Arc<dyn EventStore>Event store
event_bus: Arc<dyn EventBus>Realtime event bus
config: ThreadRuntimeConfigConfiguration
Implementations§
Source§impl ThreadRuntime
impl ThreadRuntime
Sourcepub fn new(thread: Thread, event_store: Arc<dyn EventStore>) -> Self
pub fn new(thread: Thread, event_store: Arc<dyn EventStore>) -> Self
Create a new thread runtime
Sourcepub fn new_with_bus(
thread: Thread,
event_store: Arc<dyn EventStore>,
event_bus: Arc<dyn EventBus>,
) -> Self
pub fn new_with_bus( thread: Thread, event_store: Arc<dyn EventStore>, event_bus: Arc<dyn EventBus>, ) -> Self
Create a new thread runtime with custom event bus
Sourcepub fn with_policy(
thread: Thread,
event_store: Arc<dyn EventStore>,
policy: Arc<dyn ConcurrencyPolicy>,
) -> Self
pub fn with_policy( thread: Thread, event_store: Arc<dyn EventStore>, policy: Arc<dyn ConcurrencyPolicy>, ) -> Self
Create a new thread runtime with custom policy
Sourcepub fn with_policy_and_bus(
thread: Thread,
event_store: Arc<dyn EventStore>,
policy: Arc<dyn ConcurrencyPolicy>,
event_bus: Arc<dyn EventBus>,
) -> Self
pub fn with_policy_and_bus( thread: Thread, event_store: Arc<dyn EventStore>, policy: Arc<dyn ConcurrencyPolicy>, event_bus: Arc<dyn EventBus>, ) -> Self
Create a new thread runtime with custom policy and event bus
Sourcepub fn with_config(
thread: Thread,
event_store: Arc<dyn EventStore>,
config: ThreadRuntimeConfig,
) -> Self
pub fn with_config( thread: Thread, event_store: Arc<dyn EventStore>, config: ThreadRuntimeConfig, ) -> Self
Create a new thread runtime with custom config
Sourcepub fn with_config_and_bus(
thread: Thread,
event_store: Arc<dyn EventStore>,
config: ThreadRuntimeConfig,
event_bus: Arc<dyn EventBus>,
) -> Self
pub fn with_config_and_bus( thread: Thread, event_store: Arc<dyn EventStore>, config: ThreadRuntimeConfig, event_bus: Arc<dyn EventBus>, ) -> Self
Create a new thread runtime with custom config and event bus
Sourcepub fn with_policy_and_config(
thread: Thread,
event_store: Arc<dyn EventStore>,
policy: Arc<dyn ConcurrencyPolicy>,
config: ThreadRuntimeConfig,
) -> Self
pub fn with_policy_and_config( thread: Thread, event_store: Arc<dyn EventStore>, policy: Arc<dyn ConcurrencyPolicy>, config: ThreadRuntimeConfig, ) -> Self
Create a new thread runtime with custom policy and config
Sourcepub fn with_policy_config_and_bus(
thread: Thread,
event_store: Arc<dyn EventStore>,
policy: Arc<dyn ConcurrencyPolicy>,
config: ThreadRuntimeConfig,
event_bus: Arc<dyn EventBus>,
) -> Self
pub fn with_policy_config_and_bus( thread: Thread, event_store: Arc<dyn EventStore>, policy: Arc<dyn ConcurrencyPolicy>, config: ThreadRuntimeConfig, event_bus: Arc<dyn EventBus>, ) -> Self
Create a new thread runtime with custom policy, config, and event bus
Sourcepub async fn running_state(&self) -> RunningState
pub async fn running_state(&self) -> RunningState
Get the current running state
Sourcepub async fn handle_event(
&self,
event: Event,
) -> Result<HandleEventResult, RuntimeError>
pub async fn handle_event( &self, event: Event, ) -> Result<HandleEventResult, RuntimeError>
Handle a new event
Sourcepub async fn cancel_all_active(&self)
pub async fn cancel_all_active(&self)
Cancel all active interactions
Sourcepub async fn get_interaction(&self, id: &str) -> Option<Interaction>
pub async fn get_interaction(&self, id: &str) -> Option<Interaction>
Get an interaction by ID
Sourcepub async fn add_task_to_interaction(
&self,
id: &str,
task_id: TaskId,
) -> Result<(), RuntimeError>
pub async fn add_task_to_interaction( &self, id: &str, task_id: TaskId, ) -> Result<(), RuntimeError>
Add a task to an interaction
Sourcepub async fn find_resume_interaction(
&self,
event: &Event,
) -> Option<InteractionId>
pub async fn find_resume_interaction( &self, event: &Event, ) -> Option<InteractionId>
Find a waiting interaction that can be resumed by this event.
Sourcepub async fn append_event_to_interaction(
&self,
interaction_id: &str,
event: Event,
) -> Result<(), RuntimeError>
pub async fn append_event_to_interaction( &self, interaction_id: &str, event: Event, ) -> Result<(), RuntimeError>
Append an event to an existing interaction and keep event/interaction IDs consistent.
Sourcepub fn subscribe_events(&self) -> Receiver<Event>
pub fn subscribe_events(&self) -> Receiver<Event>
Subscribe to the realtime event stream.
Sourcepub async fn resume_interaction(&self, id: &str) -> Result<(), RuntimeError>
pub async fn resume_interaction(&self, id: &str) -> Result<(), RuntimeError>
Mark a waiting interaction active so execution can continue.
Sourcepub async fn update_interaction_state(
&self,
id: &str,
state: InteractionState,
) -> Result<(), RuntimeError>
pub async fn update_interaction_state( &self, id: &str, state: InteractionState, ) -> Result<(), RuntimeError>
Update an interaction’s state
Sourcepub async fn complete_interaction(&self, id: &str) -> Result<(), RuntimeError>
pub async fn complete_interaction(&self, id: &str) -> Result<(), RuntimeError>
Complete an interaction
Sourcepub async fn fail_interaction(&self, id: &str) -> Result<(), RuntimeError>
pub async fn fail_interaction(&self, id: &str) -> Result<(), RuntimeError>
Fail an interaction
Sourcepub async fn active_interaction_ids(&self) -> Vec<InteractionId>
pub async fn active_interaction_ids(&self) -> Vec<InteractionId>
Get all active interaction IDs
Sourcepub async fn query_history(
&self,
limit: usize,
) -> Result<Vec<Event>, RuntimeError>
pub async fn query_history( &self, limit: usize, ) -> Result<Vec<Event>, RuntimeError>
Query recent events for this thread
Sourcepub async fn cleanup_completed(&self)
pub async fn cleanup_completed(&self)
Cleanup completed interactions
Auto Trait Implementations§
impl !Freeze for ThreadRuntime
impl !RefUnwindSafe for ThreadRuntime
impl Send for ThreadRuntime
impl Sync for ThreadRuntime
impl Unpin for ThreadRuntime
impl UnsafeUnpin for ThreadRuntime
impl !UnwindSafe for ThreadRuntime
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