pub struct ConcurrentState { /* private fields */ }Expand description
Thread-safe wrapper for workflow state during parallel execution.
Uses Arc<RwLock<T>> to allow multiple concurrent reads with exclusive writes.
This is optimal for workflow execution where:
- Multiple tasks may read state concurrently
- Only the executor writes state updates
§Example
ⓘ
let state = ConcurrentState::new(WorkflowState::new("workflow-1"));
// Concurrent reads (tasks checking state)
{
let reader = state.read().unwrap();
assert_eq!(reader.status, WorkflowStatus::Running);
}
// Exclusive write (executor updating state)
{
let mut writer = state.write().unwrap();
writer.status = WorkflowStatus::Completed;
}Implementations§
Source§impl ConcurrentState
impl ConcurrentState
Sourcepub fn new(state: WorkflowState) -> Self
pub fn new(state: WorkflowState) -> Self
Creates a new ConcurrentState from a WorkflowState.
Sourcepub fn read(
&self,
) -> Result<RwLockReadGuard<'_, WorkflowState>, PoisonError<RwLockReadGuard<'_, WorkflowState>>>
pub fn read( &self, ) -> Result<RwLockReadGuard<'_, WorkflowState>, PoisonError<RwLockReadGuard<'_, WorkflowState>>>
Sourcepub fn write(
&self,
) -> Result<RwLockWriteGuard<'_, WorkflowState>, PoisonError<RwLockWriteGuard<'_, WorkflowState>>>
pub fn write( &self, ) -> Result<RwLockWriteGuard<'_, WorkflowState>, PoisonError<RwLockWriteGuard<'_, WorkflowState>>>
Sourcepub fn try_read(&self) -> Option<RwLockReadGuard<'_, WorkflowState>>
pub fn try_read(&self) -> Option<RwLockReadGuard<'_, WorkflowState>>
Attempts to acquire a read lock without blocking.
§Returns
Some(guard)if the lock was acquired immediatelyNoneif the lock is held by a writer
Sourcepub fn try_write(&self) -> Option<RwLockWriteGuard<'_, WorkflowState>>
pub fn try_write(&self) -> Option<RwLockWriteGuard<'_, WorkflowState>>
Attempts to acquire a write lock without blocking.
§Returns
Some(guard)if the lock was acquired immediatelyNoneif the lock is held by another reader or writer
Trait Implementations§
Source§impl Clone for ConcurrentState
impl Clone for ConcurrentState
Source§fn clone(&self) -> ConcurrentState
fn clone(&self) -> ConcurrentState
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Send for ConcurrentState
impl Sync for ConcurrentState
Auto Trait Implementations§
impl Freeze for ConcurrentState
impl RefUnwindSafe for ConcurrentState
impl Unpin for ConcurrentState
impl UnsafeUnpin for ConcurrentState
impl UnwindSafe for ConcurrentState
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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 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>
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