#![allow(rustdoc::redundant_explicit_links)]
#![allow(rustdoc::broken_intra_doc_links)]
#[derive(Clone, Debug)]
pub struct Publisher {
inner: std::sync::Arc<dyn super::stub::dynamic::Publisher>,
}
impl Publisher {
pub fn from_stub<T>(stub: T) -> Self
where
T: super::stub::Publisher + 'static,
{
Self {
inner: std::sync::Arc::new(stub),
}
}
pub(crate) async fn new(
config: gaxi::options::ClientConfig,
) -> gax::client_builder::Result<Self> {
let inner = Self::build_inner(config).await?;
Ok(Self { inner })
}
async fn build_inner(
conf: gaxi::options::ClientConfig,
) -> gax::client_builder::Result<std::sync::Arc<dyn super::stub::dynamic::Publisher>> {
if gaxi::options::tracing_enabled(&conf) {
return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
}
Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
}
async fn build_transport(
conf: gaxi::options::ClientConfig,
) -> gax::client_builder::Result<impl super::stub::Publisher> {
super::transport::Publisher::new(conf).await
}
async fn build_with_tracing(
conf: gaxi::options::ClientConfig,
) -> gax::client_builder::Result<impl super::stub::Publisher> {
Self::build_transport(conf)
.await
.map(super::tracing::Publisher::new)
}
pub fn publish(&self) -> super::builder::publisher::Publish {
super::builder::publisher::Publish::new(self.inner.clone())
}
}