use super::{Configuration, Task};
use crate::SomeExecutor;
use crate::observer::{Observer, ObserverNotified};
use std::convert::Infallible;
use std::future::Future;
use std::task::Poll;
impl<F: Future<Output = ()>, N> Task<F, N> {
pub fn spawn_current(self)
where
F: Send + 'static,
N: ObserverNotified<()> + Send + 'static,
{
let mut executor = crate::current_executor::current_executor();
executor.spawn(self).detach();
}
pub fn spawn_local_current(self)
where
F: 'static,
N: ObserverNotified<()> + 'static,
{
todo!("Not yet implemented");
}
pub fn spawn_static_current(self)
where
F: 'static,
N: ObserverNotified<()> + 'static,
{
crate::thread_executor::thread_static_executor(|executor| {
executor
.clone_box()
.spawn_static_objsafe(self.into_objsafe_static())
.detach();
});
}
}
impl<F: Future, N> Task<F, N> {
pub fn pin_current(self) -> impl Future<Output = F::Output> + Send
where
F: 'static,
F::Output: Send,
{
{
let mut executor = crate::thread_executor::thread_static_executor(|e| e.clone_box());
crate::thread_executor::pin_static_to_thread(&mut executor, self)
}
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Default)]
pub struct DefaultFuture;
impl Future for DefaultFuture {
type Output = ();
fn poll(
self: std::pin::Pin<&mut Self>,
_: &mut std::task::Context<'_>,
) -> std::task::Poll<Self::Output> {
Poll::Ready(())
}
}
impl Default for Task<DefaultFuture, Infallible> {
fn default() -> Self {
Task::with_notifications(
"".to_string(),
Configuration::default(),
None,
DefaultFuture,
)
}
}