pub struct AsyncBroker { /* private fields */ }Expand description
Publish-subscribe broker handle.
§Example usage
use celp_sdk::async_broker::{AsyncBroker, IntoPublisher, IntoSubscriber, Subscribe};
use futures::StreamExt;
let broker = AsyncBroker::new().unwrap();
let publisher = broker.clone().into_publisher().await.unwrap();
tokio::spawn(async {
let mut subscriber = broker.into_subscriber().await.unwrap();
subscriber
.subscribe("example.channel")
.await
.unwrap();
// The `.boxed()` call can usually be omitted; it is included here due to
// https://github.com/rust-lang/rust/issues/100013
let mut stream = subscriber.into_message_stream().await.boxed();
while let Some(msg) = stream.next().await {
// handle `msg`
}
});
// You can use `publisher.publish()` etc. to publish your own messagesImplementations§
Source§impl AsyncBroker
impl AsyncBroker
Sourcepub fn new() -> Result<Self, SubscribeError>
pub fn new() -> Result<Self, SubscribeError>
Create a new instance of broker with default config
Trait Implementations§
Source§impl Clone for AsyncBroker
impl Clone for AsyncBroker
Source§fn clone(&self) -> AsyncBroker
fn clone(&self) -> AsyncBroker
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl IntoPublisher for AsyncBroker
impl IntoPublisher for AsyncBroker
fn into_publisher<'async_trait>(
self,
) -> Pin<Box<dyn Future<Output = Result<impl Publish, PublishError>> + Send + 'async_trait>>where
Self: 'async_trait,
Source§impl IntoSubscriber for AsyncBroker
impl IntoSubscriber for AsyncBroker
fn into_subscriber<'async_trait>(
self,
) -> Pin<Box<dyn Future<Output = Result<impl Subscribe, SubscribeError>> + Send + 'async_trait>>where
Self: 'async_trait,
Auto Trait Implementations§
impl Freeze for AsyncBroker
impl RefUnwindSafe for AsyncBroker
impl Send for AsyncBroker
impl Sync for AsyncBroker
impl Unpin for AsyncBroker
impl UnwindSafe for AsyncBroker
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more