Skip to content

Instantly share code, notes, and snippets.

@tomatophobia
Last active August 26, 2023 08:55
Show Gist options
  • Save tomatophobia/c02ed0a73cb18c46216d9e3551a24173 to your computer and use it in GitHub Desktop.
Save tomatophobia/c02ed0a73cb18c46216d9e3551a24173 to your computer and use it in GitHub Desktop.
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