Skip to content

Commit

Permalink
Make examples up to date
Browse files Browse the repository at this point in the history
  • Loading branch information
n1ghtmare authored and caspervonb committed Apr 5, 2023
1 parent bbe9a84 commit 0a93981
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions async-nats/examples/concurrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ async fn main() -> Result<(), async_nats::Error> {
.await?;
}

// Flush the internal buffer and ensure that all messages are sent.
client.flush().await?;

// Iterate over messages concurrently.
// for_each_concurrent allows us to not wait for time-consuming operation and receive next
// message immediately.
Expand Down
5 changes: 5 additions & 0 deletions async-nats/examples/jetstream_pull.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ async fn main() -> Result<(), async_nats::Error> {
for i in 0..10 {
jetstream
.publish(format!("events.{i}"), "data".into())
// The first `await` sends the publish
.await?
// The second `await` awaits a publish acknowledgement.
// This can be skipped (for the cost of processing guarantee)
// or deferred to not block another `publish`
.await?;
}

Expand Down
2 changes: 1 addition & 1 deletion async-nats/examples/pub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ async fn main() -> Result<(), async_nats::Error> {
let now = Instant::now();
let subject = String::from("foo");
let dat = Bytes::from("bar");
client.flush().await?;
for _ in 0..10_000_000 {
client.publish(subject.clone(), dat.clone()).await?;
}
client.flush().await?;

println!("published in {:?}", now.elapsed());

Expand Down

0 comments on commit 0a93981

Please sign in to comment.