Skip to content

Commit

Permalink
Normalize error type used in subscribe methods
Browse files Browse the repository at this point in the history
  • Loading branch information
caspervonb committed Jun 21, 2022
1 parent 7013871 commit eeb21ce
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
11 changes: 5 additions & 6 deletions async-nats/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl Client {
/// # Examples
/// ```
/// # #[tokio::main]
/// # async fn main() -> std::io::Result<()> {
/// # async fn main() -> Result<(), async_nats::Error> {
/// # let mut nc = async_nats::connect("demo.nats.io").await?;
/// let reply = nc.new_inbox();
/// let rsub = nc.subscribe(reply).await?;
Expand All @@ -172,11 +172,11 @@ impl Client {
&self,
subject: String,
queue_group: String,
) -> Result<Subscriber, io::Error> {
) -> Result<Subscriber, Error> {
self._subscribe(subject, Some(queue_group)).await
}

pub async fn subscribe(&self, subject: String) -> Result<Subscriber, io::Error> {
pub async fn subscribe(&self, subject: String) -> Result<Subscriber, Error> {
self._subscribe(subject, None).await
}

Expand All @@ -187,7 +187,7 @@ impl Client {
&self,
subject: String,
queue_group: Option<String>,
) -> Result<Subscriber, io::Error> {
) -> Result<Subscriber, Error> {
let sid = self.next_subscription_id.fetch_add(1, Ordering::Relaxed);
let (sender, receiver) = mpsc::channel(self.subscription_capacity);

Expand All @@ -198,8 +198,7 @@ impl Client {
queue_group,
sender,
})
.await
.unwrap();
.await?;

Ok(Subscriber::new(sid, self.sender.clone(), receiver))
}
Expand Down
4 changes: 2 additions & 2 deletions async-nats/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
//! # use std::time::Instant;
//!
//! # #[tokio::main]
//! # async fn main() -> Result<(), Box<dyn Error>> {
//! # async fn main() -> Result<(), async_nats::Error> {
//! let client = async_nats::connect("demo.nats.io").await?;
//!
//! let mut subscriber = client.subscribe("foo".into()).await.unwrap();
Expand Down Expand Up @@ -930,7 +930,7 @@ impl Subscriber {
/// # Examples
/// ```
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// # async fn main() -> Result<(), async_nats::Error> {
/// let client = async_nats::connect("demo.nats.io").await?;
///
/// let mut subscriber = client.subscribe("foo".into()).await?;
Expand Down

0 comments on commit eeb21ce

Please sign in to comment.