Skip to main content

base_scheduler/
blocking_error.rs

1// Released under the MIT License.
2// Copyright, 2026, by Samuel Williams.
3
4use std::{fmt, io};
5
6/// Blocking work could not be admitted. Job completion separately reports `TaskError`.
7#[derive(Debug)]
8pub enum BlockingError {
9    Cancelled,
10    SchedulerClosed,
11    /// The dedicated pool could not start its worker threads.
12    Io(io::Error),
13}
14
15impl fmt::Display for BlockingError {
16    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
17        match self {
18            Self::Cancelled => formatter.write_str("blocking admission cancelled"),
19            Self::SchedulerClosed => formatter.write_str("the scheduler is closed"),
20            Self::Io(error) => error.fmt(formatter),
21        }
22    }
23}
24
25impl std::error::Error for BlockingError {
26    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
27        match self {
28            Self::Io(error) => Some(error),
29            _ => None,
30        }
31    }
32}