use crate::error::ExecutorResult;
use crate::{Priority, Task, TaskHandle};
pub trait TaskSpawner: Send + Sync + 'static {
fn spawn<T>(&self, task: T) -> ExecutorResult<TaskHandle<T::Output>>
where
T: Task + Send + 'static;
fn spawn_async<F>(&self, future: F) -> ExecutorResult<TaskHandle<F::Output>>
where
F: core::future::Future + Send + 'static,
F::Output: Send + 'static;
fn spawn_blocking<F, R>(&self, func: F) -> ExecutorResult<TaskHandle<R>>
where
F: FnOnce() -> R + Send + 'static,
R: Send + 'static;
fn spawn_detached<F>(&self, func: F) -> ExecutorResult<()>
where
F: FnOnce() + Send + 'static,
{
self.spawn_blocking(func).map(drop)
}
fn spawn_with_priority<T>(
&self,
task: T,
priority: Priority,
locality_hint: Option<usize>,
) -> ExecutorResult<TaskHandle<T::Output>>
where
T: Task + Send + 'static;
fn spawn_local<T>(&self, task: T) -> ExecutorResult<TaskHandle<T::Output>>
where
T: Task + 'static,
{
self.spawn(task)
}
}