use std::time::{
Duration,
Instant,
};
use qubit_function::{
Callable,
Runnable,
};
use crate::service::{
ExecutorService,
SubmissionError,
};
pub trait ScheduledExecutorService: ExecutorService {
#[inline]
fn schedule<T, E>(
&self,
delay: Duration,
task: T,
) -> Result<Self::TrackedHandle<(), E>, SubmissionError>
where
T: Runnable<E> + Send + 'static,
E: Send + 'static,
{
let mut task = task;
self.schedule_callable(delay, move || task.run())
}
#[inline]
fn schedule_callable<C, R, E>(
&self,
delay: Duration,
task: C,
) -> Result<Self::TrackedHandle<R, E>, SubmissionError>
where
C: Callable<R, E> + Send + 'static,
R: Send + 'static,
E: Send + 'static,
{
self.schedule_callable_at(Instant::now() + delay, task)
}
#[inline]
fn schedule_at<T, E>(
&self,
instant: Instant,
task: T,
) -> Result<Self::TrackedHandle<(), E>, SubmissionError>
where
T: Runnable<E> + Send + 'static,
E: Send + 'static,
{
let mut task = task;
self.schedule_callable_at(instant, move || task.run())
}
fn schedule_callable_at<C, R, E>(
&self,
instant: Instant,
task: C,
) -> Result<Self::TrackedHandle<R, E>, SubmissionError>
where
C: Callable<R, E> + Send + 'static,
R: Send + 'static,
E: Send + 'static;
}