Skip to main content

qubit_executor/service/
executor_service_lifecycle.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/// Lifecycle state for a managed executor service.
12///
13/// The lifecycle is an admission and termination state machine shared by
14/// [`ExecutorService`](super::ExecutorService) implementations:
15///
16/// * [`Running`](Self::Running) accepts new tasks.
17/// * [`ShuttingDown`](Self::ShuttingDown) is entered by
18///   [`ExecutorService::shutdown`](super::ExecutorService::shutdown). It
19///   rejects new tasks but lets already accepted work finish normally.
20/// * [`Stopping`](Self::Stopping) is entered by
21///   [`ExecutorService::stop`](super::ExecutorService::stop). It rejects new
22///   tasks and asks the implementation to cancel or abort accepted work that
23///   can still be stopped.
24/// * [`Terminated`](Self::Terminated) means shutdown or stop has been requested
25///   and no accepted work remains active.
26///
27/// `ShuttingDown` and `Stopping` are both non-running states. The distinction is
28/// what happens to accepted work: orderly shutdown preserves accepted work,
29/// while abrupt stop is a best-effort cancellation or abort request. Already
30/// running blocking code or OS threads may not be forcibly stopped; concrete
31/// services document those runtime-specific limits.
32#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
33pub enum ExecutorServiceLifecycle {
34    /// The service accepts new tasks and may have accepted work in progress.
35    Running = 0,
36
37    /// Graceful shutdown has started.
38    ///
39    /// The service rejects new submissions, but work accepted before
40    /// [`ExecutorService::shutdown`](super::ExecutorService::shutdown) is
41    /// allowed to finish normally.
42    ShuttingDown = 1,
43
44    /// Abrupt stop has started.
45    ///
46    /// The service rejects new submissions and is cancelling or aborting
47    /// accepted work it can still stop. Work that is already running in a form
48    /// the runtime cannot interrupt may continue until that work returns.
49    Stopping = 2,
50
51    /// The service no longer accepts tasks and has no accepted work in progress.
52    ///
53    /// This state is reached only after shutdown or stop has been requested and
54    /// all accepted work has completed, been cancelled, been dropped by its
55    /// runner endpoint, or been aborted.
56    Terminated = 3,
57}