Skip to main content

ThreadRuntime

Struct ThreadRuntime 

Source
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: ThreadRuntimeConfig

Configuration

Implementations§

Source§

impl ThreadRuntime

Source

pub fn new(thread: Thread, event_store: Arc<dyn EventStore>) -> Self

Create a new thread runtime

Source

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

Source

pub fn with_policy( thread: Thread, event_store: Arc<dyn EventStore>, policy: Arc<dyn ConcurrencyPolicy>, ) -> Self

Create a new thread runtime with custom policy

Source

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

Source

pub fn with_config( thread: Thread, event_store: Arc<dyn EventStore>, config: ThreadRuntimeConfig, ) -> Self

Create a new thread runtime with custom config

Source

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

Source

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

Source

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

Source

pub async fn thread_id(&self) -> ThreadId

Get the thread ID

Source

pub async fn running_state(&self) -> RunningState

Get the current running state

Source

pub async fn handle_event( &self, event: Event, ) -> Result<HandleEventResult, RuntimeError>

Handle a new event

Source

pub async fn cancel_all_active(&self)

Cancel all active interactions

Source

pub async fn get_interaction(&self, id: &str) -> Option<Interaction>

Get an interaction by ID

Source

pub async fn add_task_to_interaction( &self, id: &str, task_id: TaskId, ) -> Result<(), RuntimeError>

Add a task to an interaction

Source

pub async fn find_resume_interaction( &self, event: &Event, ) -> Option<InteractionId>

Find a waiting interaction that can be resumed by this event.

Source

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.

Source

pub fn subscribe_events(&self) -> Receiver<Event>

Subscribe to the realtime event stream.

Source

pub async fn resume_interaction(&self, id: &str) -> Result<(), RuntimeError>

Mark a waiting interaction active so execution can continue.

Source

pub async fn update_interaction_state( &self, id: &str, state: InteractionState, ) -> Result<(), RuntimeError>

Update an interaction’s state

Source

pub async fn complete_interaction(&self, id: &str) -> Result<(), RuntimeError>

Complete an interaction

Source

pub async fn fail_interaction(&self, id: &str) -> Result<(), RuntimeError>

Fail an interaction

Source

pub async fn active_interaction_ids(&self) -> Vec<InteractionId>

Get all active interaction IDs

Source

pub async fn query_history( &self, limit: usize, ) -> Result<Vec<Event>, RuntimeError>

Query recent events for this thread

Source

pub async fn cleanup_completed(&self)

Cleanup completed interactions

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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