mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-22 10:36:06 +01:00
Add onFailure methods to AsyncAttempt class.
This commit is contained in:
parent
533e843cdb
commit
e0d0ee0ad0
@ -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<T, F extends FailureReason> {
|
||||
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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user