use std::pin::Pin;
use crate::prelude::*;
#[allow(refining_impl_trait)]
pub trait Handler: Send + Sync {
const QUEUE: &'static str;
fn process(
&self,
queue: &SimpleQueue,
job: &Job,
) -> impl Future<Output = Result<JobResult, BoxDynError>> + Send;
fn queue(&self) -> &'static str {
Self::QUEUE
}
}
pub(crate) type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
pub(crate) trait DynJobHandler: Send + Sync {
fn process_dyn<'a>(
&'a self,
queue: &'a SimpleQueue,
job: &'a Job,
) -> BoxFuture<'a, Result<JobResult, BoxDynError>>;
}
impl<T: Handler> DynJobHandler for T {
fn process_dyn<'a>(
&'a self,
queue: &'a SimpleQueue,
job: &'a Job,
) -> BoxFuture<'a, Result<JobResult, BoxDynError>> {
Box::pin(self.process(queue, job))
}
}