Skip to content

Commit

Permalink
Merge pull request #3099 from Multiverse/ben/mv5/AsyncAttempt
Browse files Browse the repository at this point in the history
Add onFailure methods to AsyncAttempt class
  • Loading branch information
benwoo1110 authored Aug 29, 2024
2 parents 533e843 + e0d0ee0 commit fe79580
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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;
Expand Down Expand Up @@ -67,6 +68,19 @@ public AsyncAttempt<T, F> onSuccess(Runnable runnable) {
return new AsyncAttempt<>(future.thenApply(attempt -> attempt.onSuccess(runnable)));
}

public AsyncAttempt<T, F> 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<T, F> onFailure(Consumer<Attempt.Failure<T, F>> consumer) {
return new AsyncAttempt<>(future.thenApply(attempt -> attempt.onFailure(consumer)));
}

public AsyncAttempt<T, F> onFailureReason(Consumer<F> consumer) {
return new AsyncAttempt<>(future.thenApply(attempt -> attempt.onFailureReason(consumer)));
}

public Attempt<T, F> toAttempt() {
return future.join();
}
Expand Down

0 comments on commit fe79580

Please sign in to comment.