pub struct ConditionalTask { /* private fields */ }Expand description
Task that executes conditionally based on another task’s result.
The condition task is executed first, then based on its result, either the then_task or else_task is executed.
Implementations§
Source§impl ConditionalTask
impl ConditionalTask
Sourcepub fn new(
condition_task: Box<dyn WorkflowTask>,
then_task: Box<dyn WorkflowTask>,
else_task: Option<Box<dyn WorkflowTask>>,
) -> Self
pub fn new( condition_task: Box<dyn WorkflowTask>, then_task: Box<dyn WorkflowTask>, else_task: Option<Box<dyn WorkflowTask>>, ) -> Self
Creates a new conditional task.
§Arguments
condition_task- Task whose result determines the branchthen_task- Task executed on successelse_task- Optional task executed on failure
§Example
ⓘ
let condition = Box::new(FunctionTask::new(
TaskId::new("check"),
"Check".to_string(),
|_ctx| async { Ok(TaskResult::Success) }
));
let then_branch = Box::new(FunctionTask::new(
TaskId::new("then"),
"Then".to_string(),
|_ctx| async { Ok(TaskResult::Success) }
));
let task = ConditionalTask::new(condition, then_branch, None);Sourcepub fn with_else(
condition_task: Box<dyn WorkflowTask>,
then_task: Box<dyn WorkflowTask>,
else_task: Box<dyn WorkflowTask>,
) -> Self
pub fn with_else( condition_task: Box<dyn WorkflowTask>, then_task: Box<dyn WorkflowTask>, else_task: Box<dyn WorkflowTask>, ) -> Self
Creates a conditional task with an else branch.
Trait Implementations§
Source§impl WorkflowTask for ConditionalTask
impl WorkflowTask for ConditionalTask
Source§fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
context: &'life1 TaskContext,
) -> Pin<Box<dyn Future<Output = Result<TaskResult, TaskError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
context: &'life1 TaskContext,
) -> Pin<Box<dyn Future<Output = Result<TaskResult, TaskError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Executes the task with the provided context. Read more
Source§fn compensation(&self) -> Option<CompensationAction>
fn compensation(&self) -> Option<CompensationAction>
Returns the compensation action for this task (if any). Read more
Auto Trait Implementations§
impl Freeze for ConditionalTask
impl !RefUnwindSafe for ConditionalTask
impl Send for ConditionalTask
impl Sync for ConditionalTask
impl Unpin for ConditionalTask
impl UnsafeUnpin for ConditionalTask
impl !UnwindSafe for ConditionalTask
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> 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