1use std::future::Future;
2use std::pin::Pin;
3use tokio::task::JoinHandle;
4
5type ExecutionFn<T, E> = Box<
6 dyn Fn(Pin<Box<dyn Future<Output = Result<T, E>> + Send + 'static>>) -> JoinHandle<Result<T, E>>
7 + Send
8 + 'static,
9>;
10
11use derive_getters::Getters;
12
13#[derive(Getters)]
14pub struct ExecutionMode<T, E> {
15 pub(crate) execution_fn: Option<ExecutionFn<T, E>>,
16}
17
18impl<T, E> ExecutionMode<T, E> {
19 pub fn true_async() -> Self {
23 Self { execution_fn: None }
24 }
25
26 pub fn pseudo_async<F>(execution_fn: F) -> Self
31 where
32 F: Fn(
33 Pin<Box<dyn Future<Output = Result<T, E>> + Send + 'static>>,
34 ) -> JoinHandle<Result<T, E>>
35 + Send
36 + 'static,
37 {
38 Self {
39 execution_fn: Some(Box::new(execution_fn)),
40 }
41 }
42
43 }