Skip to main content

async_runtime/
error.rs

1use std::error::Error;
2use std::fmt;
3
4/// An error returned when a task cannot be accepted.
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum SpawnError {
7    /// The target runtime or local domain has begun shutting down.
8    Closed,
9}
10
11impl fmt::Display for SpawnError {
12    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
13        match self {
14            Self::Closed => f.write_str("the target executor is closed"),
15        }
16    }
17}
18
19impl Error for SpawnError {}
20
21/// The result of a shutdown operation with a deadline.
22#[derive(Debug, Clone, Copy, PartialEq, Eq)]
23pub enum ShutdownOutcome {
24    /// Every accepted task completed before the deadline.
25    Completed,
26    /// The deadline elapsed and the remaining tasks were cancelled.
27    TimedOut {
28        /// Number of accepted tasks that had not completed at the deadline.
29        remaining_tasks: usize,
30    },
31}
32
33/// An error raised while shutting down a general runtime.
34#[derive(Debug, Clone, Copy, PartialEq, Eq)]
35pub enum ShutdownError {
36    /// Shutdown was invoked by one of this runtime's own worker threads.
37    CalledFromWorker,
38    /// At least one worker thread panicked while being joined.
39    WorkerPanicked,
40}
41
42impl fmt::Display for ShutdownError {
43    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
44        match self {
45            Self::CalledFromWorker => {
46                f.write_str("a runtime cannot synchronously join its current worker")
47            }
48            Self::WorkerPanicked => f.write_str("a runtime worker panicked"),
49        }
50    }
51}
52
53impl Error for ShutdownError {}