use std::{future::Future, pin::Pin};
pub trait Executor: Clone + Sync + Send + 'static {
fn spawn<F>(&self, future: F)
where
F: Future + Send + 'static,
F::Output: Send;
}
pub trait Timer: Send + Sync + 'static {
fn sleep(&self, duration: std::time::Duration) -> Pin<Box<dyn EventFuture>>;
}
pub trait EventFuture: Send + Future<Output = ()> {}
impl<T> EventFuture for T where T: Future<Output = ()> + Send {}
pub trait CancelToken: Send + Sync + 'static {
fn wait(&self) -> Pin<Box<dyn EventFuture>>;
fn is_cancelled(&self) -> bool;
fn cancel(&self);
fn clone_box(&self) -> Box<dyn CancelToken>;
}
pub type BoxedCancelToken = Box<dyn CancelToken>;
impl Clone for BoxedCancelToken {
fn clone(&self) -> Self {
self.clone_box()
}
}