use super::proc::StubProc;
use crate::{
core::{
adaptor::{Adaptor, MaybeAsync},
error::ProcError,
msg::Tvf,
proc::ProcConfig,
service::ServiceError,
},
maybe_async,
};
extern crate self as prosa;
use opentelemetry::metrics::Meter;
pub trait StubAdaptor<M>
where
M: 'static
+ std::marker::Send
+ std::marker::Sync
+ std::marker::Sized
+ std::clone::Clone
+ std::fmt::Debug
+ Tvf
+ std::default::Default,
{
fn new(proc: &StubProc<M>) -> Result<Self, Box<dyn ProcError + Send + Sync>>
where
Self: Sized;
fn process_request(
&self,
service_name: &str,
request: M,
) -> MaybeAsync<Result<M, ServiceError>>;
}
#[derive(Adaptor)]
pub struct StubParotAdaptor {
#[allow(unused)]
meter: Meter,
}
impl<M> StubAdaptor<M> for StubParotAdaptor
where
M: 'static
+ std::marker::Send
+ std::marker::Sync
+ std::marker::Sized
+ std::clone::Clone
+ std::fmt::Debug
+ Tvf
+ std::default::Default,
{
fn new(proc: &StubProc<M>) -> Result<Self, Box<dyn ProcError + Send + Sync>> {
Ok(Self {
meter: proc.get_proc_param().meter("stub_adaptor"),
})
}
fn process_request(
&self,
_service_name: &str,
request: M,
) -> MaybeAsync<Result<M, ServiceError>> {
Ok(request.clone()).into()
}
}
#[derive(Adaptor)]
pub struct StubAsyncParotAdaptor {}
impl<M> StubAdaptor<M> for StubAsyncParotAdaptor
where
M: 'static
+ std::marker::Send
+ std::marker::Sync
+ std::marker::Sized
+ std::clone::Clone
+ std::fmt::Debug
+ Tvf
+ std::default::Default,
{
fn new(_proc: &StubProc<M>) -> Result<Self, Box<dyn ProcError + Send + Sync>> {
Ok(Self {})
}
fn process_request(
&self,
_service_name: &str,
request: M,
) -> MaybeAsync<Result<M, ServiceError>> {
maybe_async!(async move {
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
Ok(request)
})
}
}