pub enum TaskTerminateReason {
Timeout,
Cleanup,
DependenciesFinished,
UserRequested,
InternalError,
}Expand description
Reason for terminating a running task
Provides context about why a task termination was requested, enabling appropriate cleanup and response handling.
§Examples
§Timeout Termination
use tcrm_task::tasks::{
config::TaskConfig,
tokio::executor::TaskExecutor,
event::TaskTerminateReason
};
use tokio::sync::mpsc;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
#[cfg(windows)]
let config = TaskConfig::new("cmd").args(["/C", "timeout", "/t", "5"]); // 5 second sleep
#[cfg(unix)]
let config = TaskConfig::new("sleep").args(["5"]); // 5 second sleep
let (tx, _rx) = mpsc::channel(100);
let mut executor = TaskExecutor::new(config, tx);
executor.coordinate_start().await?;
// Terminate after 1 second
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
Ok(())
}§Cleanup Termination
use tcrm_task::tasks::{
config::TaskConfig,
tokio::executor::TaskExecutor,
event::TaskTerminateReason
};
use tokio::sync::mpsc;
use crate::tcrm_task::tasks::control::TaskControl;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
#[cfg(windows)]
let config = TaskConfig::new("cmd").args(["/C", "echo", "running"]);
#[cfg(unix)]
let config = TaskConfig::new("echo").args(["running"]);
let (tx, _rx) = mpsc::channel(100);
let mut executor = TaskExecutor::new(config, tx);
executor.coordinate_start().await?;
let reason = TaskTerminateReason::UserRequested;
executor.terminate_task(reason)?;
Ok(())
}Variants§
Timeout
Task exceeded its configured timeout
The process ran longer than the timeout_ms specified in TaskConfig
and was terminated to prevent runaway processes.
Cleanup
Task was terminated during cleanup operations
Used when terminating tasks as part of application shutdown, resource cleanup, or dependency management.
DependenciesFinished
Task was terminated because its dependencies finished
Used in task orchestration scenarios where tasks depend on other tasks and should be terminated when dependencies complete.
UserRequested
Task was terminated by explicit user request
Used when user or external library requests the task to stop.
InternalError
Task was terminated due to internal error condition
Indicates that the task encountered an unexpected error that caused it to be terminated.
Trait Implementations§
Source§impl Clone for TaskTerminateReason
impl Clone for TaskTerminateReason
Source§fn clone(&self) -> TaskTerminateReason
fn clone(&self) -> TaskTerminateReason
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more