use std::future::Future;
use crate::TaskContext;
use crate::error::HauchiwaError;
use crate::{Blueprint, graph::Handle};
impl<G> Blueprint<G>
where
G: Send + Sync + 'static,
{
pub fn load_async<R, F, Fut>(&mut self, callback: F) -> Result<Handle<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()?,
);
Ok(self.add_task((), move |ctx, ()| executor.block_on(callback(ctx))))
}
}