pub enum TaskTerminateReason {
Timeout,
Cleanup,
DependenciesFinished,
Custom(String),
}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,
async_tokio::spawner::TaskSpawner,
state::TaskTerminateReason
};
use tokio::sync::mpsc;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = TaskConfig::new("cmd").args(["/C", "ping", "127.0.0.1", "-n", "5"]); // 5 second sleep
let mut spawner = TaskSpawner::new("long-task".to_string(), config);
let (tx, _rx) = mpsc::channel(100);
spawner.start_direct(tx).await?;
// Terminate after 1 second
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
spawner.send_terminate_signal(TaskTerminateReason::Timeout).await?;
Ok(())
}§Custom Termination
use tcrm_task::tasks::{
config::TaskConfig,
async_tokio::spawner::TaskSpawner,
state::TaskTerminateReason
};
use tokio::sync::mpsc;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = TaskConfig::new("cmd").args(["/C", "echo", "running"]);
let mut spawner = TaskSpawner::new("daemon".to_string(), config);
let (tx, _rx) = mpsc::channel(100);
spawner.start_direct(tx).await?;
// Custom shutdown reason
let reason = TaskTerminateReason::Custom("User requested shutdown".to_string());
spawner.send_terminate_signal(reason).await?;
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.
Custom(String)
Task was terminated for a custom application-specific reason
Allows applications to provide specific context about why a task was terminated beyond the standard reasons.
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