Skip to content

Commit e2165af

Browse files
authored
pubsub: clarify sleep-then-stop in snippet (#2617)
Fixes #2616
1 parent a8309e5 commit e2165af

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/CreateSubscriptionAndConsumeMessages.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,13 @@ public void failed(Subscriber.State from, Throwable failure) {
6262
MoreExecutors.directExecutor());
6363
subscriber.startAsync().awaitRunning();
6464

65+
// In this example, we will pull messages for one minute (60,000ms) then stop.
66+
// In a real application, this sleep-then-stop is not necessary.
67+
// Simply call stopAsync().awaitTerminated() when the server is shutting down, etc.
6568
Thread.sleep(60000);
6669
} finally {
6770
if (subscriber != null) {
68-
subscriber.stopAsync();
71+
subscriber.stopAsync().awaitTerminated();
6972
}
7073
}
7174
}

0 commit comments

Comments
 (0)