use std::{future::Future, io};
use thiserror::Error as ThisError;
#[derive(Debug, ThisError)]
pub enum RuntimeError {
#[error("failed to create Tokio current-thread runtime: {source}")]
CreateTokioRuntime { source: io::Error },
}
pub fn block_on_current_thread<F>(future: F) -> Result<F::Output, RuntimeError>
where
F: Future,
{
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.map_err(|source| RuntimeError::CreateTokioRuntime { source })?;
Ok(runtime.block_on(future))
}