Skip to content

Commit 0986b3e

Browse files
committed
example: add bound to pubsub
1 parent 55b7fa7 commit 0986b3e

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

examples/pubsub.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,18 @@ async fn main() -> Result<()> {
4747
FieldTable::default(),
4848
)
4949
.await?;
50-
runtime.spawn(async move {
50+
let cons = runtime.spawn(async move {
5151
info!("will consume");
5252
while let Some(delivery) = consumer.next().await {
53-
let delivery = delivery.expect("error in consumer");
54-
delivery.ack(BasicAckOptions::default()).await.expect("ack");
53+
let delivery = delivery?;
54+
delivery.ack(BasicAckOptions::default()).await?;
5555
}
56+
Ok(())
5657
});
5758

5859
let payload = b"Hello world!";
5960

60-
loop {
61+
for _ in 0..1500000 {
6162
let confirm = channel_a
6263
.basic_publish(
6364
"",
@@ -70,4 +71,10 @@ async fn main() -> Result<()> {
7071
.await?;
7172
assert_eq!(confirm, Confirmation::NotRequested);
7273
}
74+
75+
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
76+
channel_b
77+
.basic_cancel("my_consumer", BasicCancelOptions::default())
78+
.await?;
79+
cons.await
7380
}

0 commit comments

Comments
 (0)