use redis::FromRedisValue;
use crate::types::Entry;
use core::future::Future;
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum TaskResultKind {
Invalid,
TempFail,
Failure,
Success,
}
pub struct TaskResult<T> {
pub data: Entry<T>,
pub kind: TaskResultKind,
}
impl TaskResultKind {
pub const fn is_need_retry(&self) -> bool {
match self {
Self::TempFail => true,
_ => false,
}
}
}
pub trait Dispatch {
type PayloadType: FromRedisValue;
type Future: Future<Output = TaskResult<Self::PayloadType>>;
fn send(&self, data: Entry<Self::PayloadType>) -> Self::Future;
}
impl<T: Dispatch> Dispatch for std::sync::Arc<T> {
type PayloadType = T::PayloadType;
type Future = T::Future;
#[inline(always)]
fn send(&self, data: Entry<Self::PayloadType>) -> Self::Future {
T::send(self, data)
}
}
impl<T: Dispatch> Dispatch for std::rc::Rc<T> {
type PayloadType = T::PayloadType;
type Future = T::Future;
#[inline(always)]
fn send(&self, data: Entry<Self::PayloadType>) -> Self::Future {
T::send(self, data)
}
}
impl<T: Dispatch> Dispatch for Box<T> {
type PayloadType = T::PayloadType;
type Future = T::Future;
#[inline(always)]
fn send(&self, data: Entry<Self::PayloadType>) -> Self::Future {
T::send(self, data)
}
}