use chateau::rt::Executor;
use hyper::rt::Executor as HyperExecutor;
#[derive(Debug, Default, Clone, Copy)]
pub struct TokioExecutor;
impl TokioExecutor {
pub fn new() -> Self {
Self
}
}
impl<F> Executor<F> for TokioExecutor
where
F: std::future::Future + Send + 'static,
F::Output: Send + 'static,
{
fn execute(&self, future: F) {
tokio::spawn(future);
}
}
impl<F> HyperExecutor<F> for TokioExecutor
where
F: std::future::Future + Send + 'static,
F::Output: Send + 'static,
{
fn execute(&self, future: F) {
tokio::spawn(future);
}
}
#[derive(Debug, Default, Clone, Copy)]
pub struct TokioCurrentThreadExecutor;
impl TokioCurrentThreadExecutor {
pub fn new() -> Self {
Self
}
}
impl<F> Executor<F> for TokioCurrentThreadExecutor
where
F: std::future::Future + 'static,
F::Output: 'static,
{
fn execute(&self, future: F) {
tokio::task::spawn_local(future);
}
}
impl<F> HyperExecutor<F> for TokioCurrentThreadExecutor
where
F: std::future::Future + 'static,
F::Output: 'static,
{
fn execute(&self, future: F) {
tokio::task::spawn_local(future);
}
}