use crate::api::error::Error;
use tokio::sync::oneshot;
use tracing::error;
use super::nacos_grpc_service::Callback;
pub(crate) fn convert<T>(result: Result<T, Error>, context: &str) -> Result<T, Error> {
result.map_err(|e| {
error!("{}: {}", context, e);
Error::ErrResult(context.to_string())
})
}
pub(crate) fn recv_response<T>(
result: Result<T, oneshot::error::RecvError>,
context: &str,
) -> Result<T, Error> {
result.map_err(|e| {
error!("{}: {}", context, e);
Error::ErrResult(context.to_string())
})
}
pub(crate) fn create_grpc_callback<T>() -> (Callback<T>, oneshot::Receiver<T>, want::Taker) {
let (gv, tk) = want::new();
let (tx, rx) = oneshot::channel::<T>();
(Callback::new(gv, tx), rx, tk)
}
pub(crate) fn unwrap_option<T>(opt: Option<T>, context: &str) -> Result<T, Error> {
opt.ok_or_else(|| {
error!("{}", context);
Error::ErrResult(context.to_string())
})
}