Last active
August 26, 2023 08:55
-
-
Save tomatophobia/c02ed0a73cb18c46216d9e3551a24173 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
default <T> CompletionStage<T> makeContextAware(CompletionStage<T> stage) { // A 인스턴스를 인자로 받음 | |
// 생략 | |
final CompletableFuture<T> future = JavaVersionSpecific.get().newContextAwareFuture(this); // B 인스턴스 생성 | |
stage.handle((result, cause) -> { // A와 B를 간접적으로 연결 | |
try (SafeCloseable ignored = push()) { | |
if (cause != null) { | |
future.completeExceptionally(cause); | |
} else { | |
future.complete(result); | |
} | |
} catch (Throwable t) { | |
future.completeExceptionally(t); | |
} | |
return null; | |
}); | |
return future; // B를 반환 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment