Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add async request_timeout #177

Merged
merged 1 commit into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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