Skip to main content

qubit_task/service/
task_status.rs

1/*******************************************************************************
2 *
3 *    Copyright (c) 2025 - 2026 Haixing Hu.
4 *
5 *    SPDX-License-Identifier: Apache-2.0
6 *
7 *    Licensed under the Apache License, Version 2.0.
8 *
9 ******************************************************************************/
10
11/// Status of a task managed by [`TaskExecutionService`](super::TaskExecutionService).
12///
13/// The status describes service-level progress, not the typed task result
14/// stored in [`TaskHandle`](qubit_executor::TaskHandle). The handle remains the source of truth for the
15/// task's success value or error value.
16///
17#[derive(Debug, Clone, Copy, PartialEq, Eq)]
18pub enum TaskStatus {
19    /// The task was accepted but has not started running.
20    Submitted,
21
22    /// A worker has started running the task.
23    Running,
24
25    /// The task completed successfully.
26    Succeeded,
27
28    /// The task ran and returned its own error value.
29    Failed,
30
31    /// The task panicked while running.
32    Panicked,
33
34    /// The task was cancelled before it started.
35    Cancelled,
36}
37
38impl TaskStatus {
39    /// Returns whether this status represents in-flight work.
40    ///
41    /// # Returns
42    ///
43    /// `true` for submitted or running tasks.
44    #[inline]
45    pub const fn is_active(self) -> bool {
46        matches!(self, Self::Submitted | Self::Running)
47    }
48}