use futures::Future;
pub trait Executor: Clone {
fn spawn(&self, future: impl Future<Output = ()> + Send + 'static);
}
#[derive(Clone, Debug, Default)]
pub struct TokioExecutor;
impl TokioExecutor {
pub fn new() -> Self {
Self
}
}
#[cfg(feature = "tokio-comp")]
impl Executor for TokioExecutor {
fn spawn(&self, future: impl Future<Output = ()> + Send + 'static) {
tokio::spawn(future);
}
}
#[derive(Clone, Debug)]
#[cfg(feature = "async-std-comp")]
pub struct AsyncStdExecutor;
#[cfg(feature = "async-std-comp")]
impl AsyncStdExecutor {
pub fn new() -> Self {
Self
}
}
#[cfg(feature = "async-std-comp")]
impl Executor for AsyncStdExecutor {
fn spawn(&self, fut: impl Future<Output = ()> + Send + 'static) {
async_std::task::spawn(async { fut.await });
}
}