use std::{error::Error, fmt};
#[non_exhaustive]
#[derive(Debug, Clone)]
pub struct ShutdownCompletion {
inner: Inner,
}
#[cfg(not(target_family = "wasm"))]
type Inner = aws_smithy_execution::ShutdownCompletion;
#[cfg(target_family = "wasm")]
type Inner = std::convert::Infallible;
impl ShutdownCompletion {
#[cfg(not(target_family = "wasm"))]
pub(crate) fn new(inner: aws_smithy_execution::ShutdownCompletion) -> Self {
Self { inner }
}
pub async fn wait(&self) -> Result<(), ShutdownError> {
#[cfg(not(target_family = "wasm"))]
return self
.inner
.wait()
.await
.map_err(ShutdownError::from_execution);
#[cfg(target_family = "wasm")]
match self.inner {}
}
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ShutdownErrorKind {
FromRuntime,
Joiner,
Completion,
ThreadPanic,
Other,
}
#[non_exhaustive]
#[derive(Debug)]
pub struct ShutdownError {
kind: ShutdownErrorKind,
source: crate::error::BoxError,
}
impl ShutdownError {
pub fn kind(&self) -> ShutdownErrorKind {
self.kind
}
}
impl ShutdownError {
#[cfg(not(target_family = "wasm"))]
fn from_execution(source: aws_smithy_execution::ShutdownError) -> Self {
use aws_smithy_execution::ShutdownErrorKind as Kind;
let kind = match source.kind() {
Kind::FromRuntime => ShutdownErrorKind::FromRuntime,
Kind::Joiner => ShutdownErrorKind::Joiner,
Kind::Completion => ShutdownErrorKind::Completion,
Kind::ThreadPanic => ShutdownErrorKind::ThreadPanic,
_ => ShutdownErrorKind::Other,
};
Self {
kind,
source: Box::new(source),
}
}
}
impl fmt::Display for ShutdownError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "managed runtime shutdown failed: {}", self.source)
}
}
impl Error for ShutdownError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
Some(self.source.as_ref())
}
}