use std::future::Future;
use std::sync::Arc;
use super::{Message, MessageKind, MessageRouter, RunOptions, TransportError};
pub trait Bus: Send + Sync {
fn send(
&self,
name: &str,
payload: Vec<u8>,
) -> impl Future<Output = Result<(), TransportError>> + Send {
self.send_message(Message::new(name, MessageKind::Command, payload))
}
fn publish(
&self,
name: &str,
payload: Vec<u8>,
) -> impl Future<Output = Result<(), TransportError>> + Send {
self.publish_message(Message::new(name, MessageKind::Event, payload))
}
fn send_message(
&self,
message: Message,
) -> impl Future<Output = Result<(), TransportError>> + Send;
fn publish_message(
&self,
message: Message,
) -> impl Future<Output = Result<(), TransportError>> + Send;
}
pub trait BusConsumer: Send + Sync {
fn listen<R: MessageRouter>(
&self,
router: Arc<R>,
options: RunOptions,
) -> impl Future<Output = Result<(), TransportError>> + Send;
fn subscribe<R: MessageRouter>(
&self,
router: Arc<R>,
options: RunOptions,
) -> impl Future<Output = Result<(), TransportError>> + Send;
}