TaskState

Enum TaskState 

Source
pub enum TaskState {
    Pending,
    Initiating,
    Running,
    Ready,
    Finished,
}
Expand description

Execution state of a task throughout its lifecycle

TaskState tracks the progression of a task from creation through completion. States transition in a defined order, enabling event-driven tasks execution.

§State Transitions

Pending → Initiating → Running → [Ready] → Finished
                            ↘
                              → Finished

The Ready state is optional and only occurs for long-running processes with a configured ready indicator.

§Examples

§State Monitoring

use tcrm_task::tasks::{config::TaskConfig, async_tokio::spawner::TaskSpawner, state::TaskState};

#[tokio::main]
async fn main() {
    let config = TaskConfig::new("cmd").args(["/C", "echo", "hello"]);
    let spawner = TaskSpawner::new("test".to_string(), config);
     
    // Initially pending
    assert_eq!(spawner.get_state().await, TaskState::Pending);
     
    // After calling start_direct(), state will progress through:
    // Pending → Initiating → Running → Finished
}

§Basic State Checking

use tcrm_task::tasks::{
    config::TaskConfig,
    async_tokio::spawner::TaskSpawner,
    state::TaskState
};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let config = TaskConfig::new("cmd").args(["/C", "echo", "hello"]);
    let spawner = TaskSpawner::new("demo".to_string(), config);

    // Check initial state
    let state = spawner.get_state().await;
    assert_eq!(state, TaskState::Pending);
    println!("Task is in {:?} state", state);

    Ok(())
}

Variants§

§

Pending

Task has been created but not yet started

Initial state when TaskSpawner is created. The task configuration exists but no process has been spawned yet.

§

Initiating

Task is being initialized and validated

Transitional state during start_direct() when configuration is being validated and the process is being prepared for spawning.

§

Running

Process is running and executing

The system process has been spawned and is actively executing. Output events may be emitted during this state.

§

Ready

Process is running and executing

Only reached by long-running processes that have a ready indicator configured. Indicates the process has completed initialization and is ready for work (e.g., web server listening on port). Useful when orchestrating dependent tasks.

§

Finished

Task execution has completed

Final state reached when the process exits normally, is terminated, or encounters an error. No further state transitions occur.

Trait Implementations§

Source§

impl Clone for TaskState

Source§

fn clone(&self) -> TaskState

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TaskState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for TaskState

Source§

fn eq(&self, other: &TaskState) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for TaskState

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.