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    /// Cancellation was requested before the closure was admitted.
10    Cancelled,
11    /// The scheduler no longer admits blocking work.
12    SchedulerClosed,
13    /// The dedicated pool could not start its worker threads.
14    Io(io::Error),
15}
16
17impl fmt::Display for BlockingError {
18    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
19        match self {
20            Self::Cancelled => formatter.write_str("blocking admission cancelled"),
21            Self::SchedulerClosed => formatter.write_str("the scheduler is closed"),
22            Self::Io(error) => error.fmt(formatter),
23        }
24    }
25}
26
27impl std::error::Error for BlockingError {
28    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
29        match self {
30            Self::Io(error) => Some(error),
31            _ => None,
32        }
33    }
34}