Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,18 @@ public void close() throws IOException {
*/
@SuppressWarnings("unchecked")
public RC_T awaitCompletion() throws InterruptedException {
completed.await();
// eventually (re)throws RuntimeException
throwFirstError();
return (RC_T) this;
try {
completed.await();
// eventually (re)throws RuntimeException
throwFirstError();
return (RC_T) this;
} finally {
try {
close();
} catch (IOException e) {
LOGGER.debug("Failed to close", e);
}
}
}

/**
Expand All @@ -99,9 +107,17 @@ public RC_T awaitCompletion() throws InterruptedException {
* before {@link ResultCallback#onComplete()} was called.
*/
public boolean awaitCompletion(long timeout, TimeUnit timeUnit) throws InterruptedException {
boolean result = completed.await(timeout, timeUnit);
throwFirstError();
return result;
try {
boolean result = completed.await(timeout, timeUnit);
throwFirstError();
return result;
} finally {
try {
close();
} catch (IOException e) {
LOGGER.debug("Failed to close", e);
}
}
}

/**
Expand Down