Skip to content

Commit 855dd2c

Browse files
diwu-sfclaude
andcommitted
Extract the client teardown steps out of close()
The try/finally left three levels of teardown inline. Pull the driver loop and the poll executor shutdown into named methods so close() reads as its two steps; the executor block is moved, not changed. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 6329ab4 commit 855dd2c

1 file changed

Lines changed: 26 additions & 17 deletions

File tree

contrib/temporal-workflowstreams/src/main/java/io/temporal/workflowstreams/WorkflowStreamClient.java

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -219,24 +219,33 @@ public void close() {
219219
try {
220220
publisher.close();
221221
} finally {
222-
for (SubscriptionDriver driver : liveSubscriptions.toArray(new SubscriptionDriver[0])) {
223-
driver.close();
224-
}
225-
ScheduledExecutorService owned;
226-
synchronized (this) {
227-
owned = ownedPollExecutor;
228-
}
229-
if (owned != null) {
230-
owned.shutdown();
231-
try {
232-
if (!owned.awaitTermination(1, TimeUnit.SECONDS)) {
233-
owned.shutdownNow();
234-
}
235-
} catch (InterruptedException e) {
236-
Thread.currentThread().interrupt();
237-
owned.shutdownNow();
238-
}
222+
stopSubscriptions();
223+
shutdownOwnedPollExecutor();
224+
}
225+
}
226+
227+
private void stopSubscriptions() {
228+
for (SubscriptionDriver driver : liveSubscriptions.toArray(new SubscriptionDriver[0])) {
229+
driver.close();
230+
}
231+
}
232+
233+
private void shutdownOwnedPollExecutor() {
234+
ScheduledExecutorService owned;
235+
synchronized (this) {
236+
owned = ownedPollExecutor;
237+
}
238+
if (owned == null) {
239+
return;
240+
}
241+
owned.shutdown();
242+
try {
243+
if (!owned.awaitTermination(1, TimeUnit.SECONDS)) {
244+
owned.shutdownNow();
239245
}
246+
} catch (InterruptedException e) {
247+
Thread.currentThread().interrupt();
248+
owned.shutdownNow();
240249
}
241250
}
242251

0 commit comments

Comments
 (0)