The task states and how to spawn new tasks has all been sorted out. All that is left at this point is to handle the thread portion of task management and to determine how to get messages from the new child task's completion back to the parent task.
95 lines
2.0 KiB
Rust
95 lines
2.0 KiB
Rust
/// The different states a Task can go through during its lifetime.
|
|
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord)]
|
|
pub enum TaskState
|
|
{
|
|
/// The state that every Task starts in.
|
|
///
|
|
/// The STARTING state can only lead to the processing state.
|
|
Starting,
|
|
|
|
/// The state that each Task is in while it is actually
|
|
/// being processed and running on a thread.
|
|
///
|
|
/// The PROCESSING state can only lead to WAITING,
|
|
/// FINISHED, or UNKNOWN states.
|
|
Processing,
|
|
|
|
/// The state a Task is in while it is waiting for child
|
|
/// tasks to switch to the FINISHED state.
|
|
///
|
|
/// The WAITING state can only lead to the DONE_WAITING
|
|
/// and UNKNOWN states.
|
|
Waiting,
|
|
|
|
/// The state a Task will be in when it is FINISHED processing
|
|
/// and ready to be destroyed.
|
|
///
|
|
/// The FINISHED state cannot lead to any states and shows that the
|
|
/// task is completed.
|
|
Finished,
|
|
|
|
/// The state a Task will be placed in if it is detected to be
|
|
/// in an inproper state during its lifetime.
|
|
Unknown
|
|
}
|
|
|
|
|
|
|
|
impl TaskState
|
|
{
|
|
/// Get a str representation of this variant.
|
|
pub fn to_str(&self) -> &'static str
|
|
{
|
|
match *self
|
|
{
|
|
TaskState::Starting =>
|
|
{
|
|
"Starting"
|
|
}
|
|
|
|
TaskState::Waiting =>
|
|
{
|
|
"Waiting"
|
|
}
|
|
|
|
TaskState::Processing =>
|
|
{
|
|
"Processing"
|
|
}
|
|
|
|
TaskState::Finished =>
|
|
{
|
|
"Finished"
|
|
}
|
|
|
|
TaskState::Unknown =>
|
|
{
|
|
"Unknown"
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Get a String representation of this variant.
|
|
pub fn to_string(&self) -> String
|
|
{
|
|
String::from(self.to_str())
|
|
}
|
|
}
|
|
|
|
impl ::std::fmt::Debug for TaskState
|
|
{
|
|
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result
|
|
{
|
|
write!(f, "{}", self.to_str())
|
|
}
|
|
}
|
|
|
|
impl ::std::fmt::Display for TaskState
|
|
{
|
|
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result
|
|
{
|
|
write!(f, "{}", self.to_str())
|
|
}
|
|
}
|
|
|