use std::future::Future;
use std::pin::Pin;
use std::sync::Arc;
use bytes::Bytes;
use crate::queue::error::{WorkQueueError, WorkQueueRecvError, WorkQueueSendError};
use crate::queue::options::NextOptions;
pub type SenderFuture<'a> =
Pin<Box<dyn Future<Output = Result<Arc<dyn SenderBackend>, WorkQueueError>> + Send + 'a>>;
pub type ReceiverFuture<'a> =
Pin<Box<dyn Future<Output = Result<Arc<dyn ReceiverBackend>, WorkQueueError>> + Send + 'a>>;
pub trait WorkQueueBackend: Send + Sync {
fn sender(&self, name: &str) -> SenderFuture<'_>;
fn receiver(&self, name: &str) -> ReceiverFuture<'_>;
}
pub trait SenderBackend: Send + Sync {
fn send(
&self,
data: Bytes,
) -> Pin<Box<dyn Future<Output = Result<(), WorkQueueSendError>> + Send + '_>>;
fn try_send(&self, data: Bytes) -> Result<(), WorkQueueSendError>;
fn close(&self) -> Pin<Box<dyn Future<Output = ()> + Send + '_>>;
}
pub trait ReceiverBackend: Send + Sync {
fn recv(
&self,
) -> Pin<Box<dyn Future<Output = Result<Option<Bytes>, WorkQueueRecvError>> + Send + '_>>;
fn recv_batch(
&self,
opts: &NextOptions,
) -> Pin<Box<dyn Future<Output = Result<Vec<Bytes>, WorkQueueRecvError>> + Send + '_>>;
fn try_recv(&self) -> Result<Option<Bytes>, WorkQueueRecvError>;
}