Skip to content

Commit

Permalink
Merge pull request #177 from erebe/master
Browse files Browse the repository at this point in the history
Add async request_timeout
  • Loading branch information
spacejam committed Apr 29, 2021
2 parents e4dcb58 + 0ec6536 commit 5f676e7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 0.9.15

## Improvements

- #177 Add support of request_timeout for async-nats

# 0.9.14

## New Features
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nats"
version = "0.9.14"
version = "0.9.15"
description = "A Rust NATS client"
authors = ["Derek Collison <derek@nats.io>", "Tyler Neely <tyler@nats.io>", "Stjepan Glavina <stjepan@nats.io>"]
edition = "2018"
Expand Down
4 changes: 2 additions & 2 deletions async-nats/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "async-nats"
version = "0.9.14"
version = "0.9.15"
description = "An async Rust NATS client"
authors = ["Derek Collison <derek@nats.io>", "Tyler Neely <tyler@nats.io>", "Stjepan Glavina <stjepan@nats.io>"]
edition = "2018"
Expand All @@ -17,7 +17,7 @@ maintenance = { status = "actively-developed" }

[dependencies]
blocking = "1.0.2"
nats = { path = "..", version = "0.9.14" }
nats = { path = "..", version = "0.9.15" }

[dev-dependencies]
smol = "1.2.5"
Expand Down
15 changes: 15 additions & 0 deletions async-nats/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,21 @@ impl Connection {
Ok(Message::new(msg))
}

/// Publishes a message and waits for the response or until the
/// timeout duration is reached
pub async fn request_timeout(
&self,
subject: &str,
msg: impl AsRef<[u8]>,
timeout: Duration,
) -> io::Result<Message> {
let subject = subject.to_string();
let msg = msg.as_ref().to_vec();
let inner = self.inner.clone();
let msg = unblock(move || inner.request_timeout(&subject, msg, timeout)).await?;
Ok(Message::new(msg))
}

/// Publishes a message and returns a subscription for awaiting the
/// response.
pub async fn request_multi(
Expand Down

0 comments on commit 5f676e7

Please sign in to comment.