use std::{
io,
sync::Arc,
};
use thiserror::Error;
#[derive(Debug, Clone, Error)]
pub enum SubmissionError {
#[error("task rejected because the executor service is shut down")]
Shutdown,
#[error("task rejected because the executor service is saturated")]
Saturated,
#[error("task rejected because the executor service failed to spawn a worker: {source}")]
WorkerSpawnFailed {
source: Arc<io::Error>,
},
}
impl PartialEq for SubmissionError {
fn eq(&self, other: &Self) -> bool {
matches!(
(self, other),
(Self::Shutdown, Self::Shutdown)
| (Self::Saturated, Self::Saturated)
| (
Self::WorkerSpawnFailed { .. },
Self::WorkerSpawnFailed { .. }
)
)
}
}
impl Eq for SubmissionError {}
impl SubmissionError {
#[inline]
pub fn worker_spawn_failed(source: io::Error) -> Self {
Self::WorkerSpawnFailed {
source: Arc::new(source),
}
}
}