use std::future::Future;
use crate::Blueprint;
use crate::TaskContext;
use crate::engine::One;
use crate::error::HauchiwaError;
impl<G> Blueprint<G>
where
G: Send + Sync + 'static,
{
pub fn load_async<R, F, Fut>(&mut self, callback: F) -> Result<One<R>, HauchiwaError>
where
G: Send + Sync + 'static,
R: Send + Sync + 'static,
F: Fn(&TaskContext<G>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = anyhow::Result<R>> + Send + 'static,
{
let executor = Box::new(
tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()?,
);
let handle = self.task().run(move |ctx| executor.block_on(callback(ctx)));
Ok(handle)
}
}