use alloc::sync::Arc;
use zerodds_dcps::{DataWriterQos, DdsType, Publisher, Result, Topic};
use crate::AsyncDataWriter;
#[derive(Clone)]
pub struct AsyncPublisher {
inner: Arc<Publisher>,
}
impl AsyncPublisher {
pub(crate) fn from_sync(inner: Publisher) -> Self {
Self {
inner: Arc::new(inner),
}
}
pub fn create_datawriter<T: DdsType + Send + Sync + 'static>(
&self,
topic: &Topic<T>,
qos: DataWriterQos,
) -> Result<AsyncDataWriter<T>> {
let writer = self.inner.create_datawriter::<T>(topic, qos)?;
Ok(AsyncDataWriter::from_sync(writer))
}
#[must_use]
pub fn as_sync(&self) -> &Publisher {
&self.inner
}
}