Skip to content

Commit 75b328f

Browse files
authored
auto close in ResultCallback#awaitCompletion (#1415)
1 parent 6086c7d commit 75b328f

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

docker-java-api/src/main/java/com/github/dockerjava/api/async/ResultCallbackTemplate.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,18 @@ public void close() throws IOException {
8787
*/
8888
@SuppressWarnings("unchecked")
8989
public RC_T awaitCompletion() throws InterruptedException {
90-
completed.await();
91-
// eventually (re)throws RuntimeException
92-
throwFirstError();
93-
return (RC_T) this;
90+
try {
91+
completed.await();
92+
// eventually (re)throws RuntimeException
93+
throwFirstError();
94+
return (RC_T) this;
95+
} finally {
96+
try {
97+
close();
98+
} catch (IOException e) {
99+
LOGGER.debug("Failed to close", e);
100+
}
101+
}
94102
}
95103

96104
/**
@@ -99,9 +107,17 @@ public RC_T awaitCompletion() throws InterruptedException {
99107
* before {@link ResultCallback#onComplete()} was called.
100108
*/
101109
public boolean awaitCompletion(long timeout, TimeUnit timeUnit) throws InterruptedException {
102-
boolean result = completed.await(timeout, timeUnit);
103-
throwFirstError();
104-
return result;
110+
try {
111+
boolean result = completed.await(timeout, timeUnit);
112+
throwFirstError();
113+
return result;
114+
} finally {
115+
try {
116+
close();
117+
} catch (IOException e) {
118+
LOGGER.debug("Failed to close", e);
119+
}
120+
}
105121
}
106122

107123
/**

0 commit comments

Comments
 (0)