#[cfg(feature = "bevy_runtime_018")]
use bevy_tasks_018 as bevy_tasks;
pub trait CompatInterface: crate::TaskInterface {
fn tokio_compat<T>(f: impl Future<Output = T> + Send) -> impl Future<Output = T> + Send;
fn spawn_tokio_task<F, T>(
&self,
future: F,
) -> Result<crate::utils::TaskHandle<Self::TaskHandle<F::Output>>, Self::SpawnError>
where
F: Future<Output = T> + Send + 'static,
T: Send + 'static,
{
self.spawn_task(Self::tokio_compat(future))
}
}
#[cfg(feature = "futures_runtime")]
impl CompatInterface for crate::futures::Runtime {
fn tokio_compat<T>(f: impl Future<Output = T> + Send) -> impl Future<Output = T> + Send {
async_compat::Compat::new(f)
}
}
#[cfg(feature = "tokio_runtime")]
impl CompatInterface for crate::tokio::Runtime {
fn tokio_compat<T>(f: impl Future<Output = T> + Send) -> impl Future<Output = T> + Send {
f
}
}
#[cfg(any(feature = "bevy_runtime", feature = "bevy_runtime_018"))]
impl<TP> CompatInterface for crate::bevy::Runtime<TP>
where
TP: std::ops::Deref<Target = bevy_tasks::TaskPool> + Sync + 'static,
{
fn tokio_compat<T>(f: impl Future<Output = T> + Send) -> impl Future<Output = T> + Send {
async_compat::Compat::new(f)
}
}