use std::{future::Future, marker::PhantomData};
pub trait Spawn<F>: 'static
where
F: Future + 'static,
{
fn spawn(&mut self, future: F);
}
#[derive(Debug)]
pub struct TokioSpawn<F> {
_phantom: PhantomData<F>,
}
impl<F> Default for TokioSpawn<F> {
fn default() -> Self {
Self {
_phantom: Default::default(),
}
}
}
impl<F> Spawn<F> for TokioSpawn<F>
where
F: Future + Send + 'static,
F::Output: Send + 'static,
{
fn spawn(&mut self, driver: F) {
tokio::spawn(driver);
}
}
#[derive(Debug)]
pub struct LevelSpawn<F> {
_phantom: PhantomData<F>,
}
impl<F> Default for LevelSpawn<F> {
fn default() -> Self {
Self {
_phantom: Default::default(),
}
}
}
impl<F> Spawn<F> for LevelSpawn<F>
where
F: Future + Send + 'static,
F::Output: Send + 'static,
{
fn spawn(&mut self, future: F) {
level_runtime::spawn_local(future);
}
}