use std::future::Future;
use crate::Reactor;
use crate::Runtime;
use crate::Tracer;
pub trait LifetimeLinkerFn<'runtime, ReactorT, InitT, ResT> {
type OutputFuture: Future<Output = ResT>;
fn call(self, arg: &'runtime Runtime<ReactorT>, init: InitT) -> Self::OutputFuture;
}
impl<'runtime, ReactorT, InitT, ResT, FutureT, FuncT>
LifetimeLinkerFn<'runtime, ReactorT, InitT, ResT> for FuncT
where
FuncT: FnOnce(&'runtime Runtime<ReactorT>, InitT) -> FutureT,
FutureT: Future<Output = ResT>,
ReactorT: Reactor + 'runtime, {
type OutputFuture = FutureT;
fn call(self, rt: &'runtime Runtime<ReactorT>, init: InitT) -> FutureT {
self(rt, init)
}
}
pub fn with_runtime_base<ReactorT, FuncT, InitT, ResT>(
reactor: ReactorT,
tracer: Tracer,
async_function: FuncT,
init: InitT,
) -> ResT
where
FuncT: for<'runtime> LifetimeLinkerFn<'runtime, ReactorT, InitT, ResT>,
ReactorT: Reactor,
{
let runtime = Runtime::<ReactorT>::new(reactor, tracer);
let future = async_function.call(&runtime, init);
runtime.nested_loop(future)
}