From e0d0ee0ad070c25aba0efe194bfbc7d8164ff4b4 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Wed, 28 Aug 2024 20:01:03 +0800 Subject: [PATCH] Add onFailure methods to AsyncAttempt class. --- .../multiverse/core/utils/result/AsyncAttempt.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/org/mvplugins/multiverse/core/utils/result/AsyncAttempt.java b/src/main/java/org/mvplugins/multiverse/core/utils/result/AsyncAttempt.java index 67b8a9a0..f57268ae 100644 --- a/src/main/java/org/mvplugins/multiverse/core/utils/result/AsyncAttempt.java +++ b/src/main/java/org/mvplugins/multiverse/core/utils/result/AsyncAttempt.java @@ -3,6 +3,7 @@ package org.mvplugins.multiverse.core.utils.result; import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.function.BiFunction; +import java.util.function.Consumer; import java.util.function.Function; import org.mvplugins.multiverse.core.utils.message.MessageReplacement; @@ -67,6 +68,19 @@ public final class AsyncAttempt { return new AsyncAttempt<>(future.thenApply(attempt -> attempt.onSuccess(runnable))); } + public AsyncAttempt onFailure(Runnable runnable) { + // TODO Not sure why we creating a new instance instead of using `this` + return new AsyncAttempt<>(future.thenApply(attempt -> attempt.onFailure(runnable))); + } + + public AsyncAttempt onFailure(Consumer> consumer) { + return new AsyncAttempt<>(future.thenApply(attempt -> attempt.onFailure(consumer))); + } + + public AsyncAttempt onFailureReason(Consumer consumer) { + return new AsyncAttempt<>(future.thenApply(attempt -> attempt.onFailureReason(consumer))); + } + public Attempt toAttempt() { return future.join(); }