use std::future::Future;
use std::pin::Pin;
use tokio::task::JoinHandle;
type ExecutionFn<T, E> = Box<
dyn Fn(Pin<Box<dyn Future<Output = Result<T, E>> + Send + 'static>>) -> JoinHandle<Result<T, E>>
+ Send
+ 'static,
>;
use derive_getters::Getters;
#[derive(Getters)]
pub struct ExecutionMode<T, E> {
pub(crate) execution_fn: Option<ExecutionFn<T, E>>,
}
impl<T, E> ExecutionMode<T, E> {
pub fn true_async() -> Self {
Self { execution_fn: None }
}
pub fn pseudo_async<F>(execution_fn: F) -> Self
where
F: Fn(
Pin<Box<dyn Future<Output = Result<T, E>> + Send + 'static>>,
) -> JoinHandle<Result<T, E>>
+ Send
+ 'static,
{
Self {
execution_fn: Some(Box::new(execution_fn)),
}
}
}