use std::future::Future;
pub trait AsyncExec: Send + Sync + 'static + Clone + std::fmt::Debug {
type AsyncJoiner<R: Send>: AsyncJoiner<R>;
type ThreadJoiner<R: Send>: ThreadJoiner<R> + Send;
fn spawn<F, R>(&self, f: F) -> Self::AsyncJoiner<R>
where
F: Future<Output = R> + Send + 'static,
R: Send + 'static;
fn spawn_detach<F, R>(&self, f: F)
where
F: Future<Output = R> + Send + 'static,
R: Send + 'static;
fn spawn_blocking<F, R>(&self, f: F) -> Self::ThreadJoiner<R>
where
F: FnOnce() -> R + Send + 'static,
R: Send + 'static;
fn block_on<F, R>(&self, f: F) -> R
where
F: Future<Output = R> + Send,
R: 'static;
}
pub trait AsyncJoiner<T>: Future<Output = Result<T, ()>> + Send + Unpin {
fn is_finished(&self) -> bool;
fn detach(self)
where
Self: Sized;
fn abort(self)
where
Self: Sized;
fn detach_boxed(self: Box<Self>);
fn abort_boxed(self: Box<Self>);
}
pub trait ThreadJoiner<T>: Future<Output = Result<T, ()>> {
fn is_finished(&self) -> bool;
}