Browse Source

Rename Publication::send to publish

master
Alex Mikhalev 4 years ago
parent
commit
87ac069eab
  1. 14
      src/lib.rs
  2. 4
      src/publication.rs

14
src/lib.rs

@ -8,7 +8,7 @@ use broker_task::{
SubscribeRequestSender, SubscribeRequestSender,
}; };
pub use message::Message; pub use message::Message;
pub use publication::{Publication, SendError}; pub use publication::{Publication, PublishError};
pub use subscription::{RecvError, Subscription}; pub use subscription::{RecvError, Subscription};
use futures::executor::block_on; use futures::executor::block_on;
@ -98,9 +98,9 @@ mod test {
let mut sub = orsb.subscribe_blocking::<TestMsg>().unwrap(); let mut sub = orsb.subscribe_blocking::<TestMsg>().unwrap();
let mut publ = orsb.advertise_blocking::<TestMsg>().unwrap(); let mut publ = orsb.advertise_blocking::<TestMsg>().unwrap();
publ.send(TestMsg(10)).unwrap(); publ.publish(TestMsg(10)).unwrap();
publ.send(TestMsg(20)).unwrap(); publ.publish(TestMsg(20)).unwrap();
publ.send(TestMsg(30)).unwrap(); publ.publish(TestMsg(30)).unwrap();
assert_eq!(sub.recv_blocking(), Ok(TestMsg(10))); assert_eq!(sub.recv_blocking(), Ok(TestMsg(10)));
assert_eq!(sub.recv_blocking(), Ok(TestMsg(20))); assert_eq!(sub.recv_blocking(), Ok(TestMsg(20)));
@ -120,9 +120,9 @@ mod test {
let mut sub = orsb.subscribe::<TestMsg>().await.unwrap(); let mut sub = orsb.subscribe::<TestMsg>().await.unwrap();
let mut publ = orsb.advertise::<TestMsg>().await.unwrap(); let mut publ = orsb.advertise::<TestMsg>().await.unwrap();
publ.send(TestMsg(10)).unwrap(); publ.publish(TestMsg(10)).unwrap();
publ.send(TestMsg(20)).unwrap(); publ.publish(TestMsg(20)).unwrap();
publ.send(TestMsg(30)).unwrap(); publ.publish(TestMsg(30)).unwrap();
assert_eq!(sub.recv().await, Ok(TestMsg(10))); assert_eq!(sub.recv().await, Ok(TestMsg(10)));
assert_eq!(sub.recv().await, Ok(TestMsg(20))); assert_eq!(sub.recv().await, Ok(TestMsg(20)));

4
src/publication.rs

@ -4,7 +4,7 @@ use crate::message::Message;
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
#[non_exhaustive] #[non_exhaustive]
pub enum SendError {} pub enum PublishError {}
#[derive(Debug)] #[derive(Debug)]
pub struct Publication<T> { pub struct Publication<T> {
@ -16,7 +16,7 @@ impl<T: Message> Publication<T> {
Publication { sender } Publication { sender }
} }
pub fn send(&mut self, message: T) -> Result<usize, SendError> { pub fn publish(&mut self, message: T) -> Result<usize, PublishError> {
match self.sender.send(message) { match self.sender.send(message) {
Ok(subscribers) => Ok(subscribers), Ok(subscribers) => Ok(subscribers),
Err(_) => Ok(0), Err(_) => Ok(0),

Loading…
Cancel
Save