mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-04-06 18:20:26 +08:00
remove isDependentSucceeded in whenComplete
This commit is contained in:
parent
eeef76594f
commit
cae32cff4c
@ -106,11 +106,11 @@ public class AddAuthlibInjectorServerPane extends StackPane implements DialogAwa
|
||||
|
||||
Task.runAsync(() -> {
|
||||
serverBeingAdded = AuthlibInjectorServer.locateServer(url);
|
||||
}).whenComplete(Schedulers.javafx(), (isDependentSucceeded, exception) -> {
|
||||
}).whenComplete(Schedulers.javafx(), exception -> {
|
||||
addServerPane.setDisable(false);
|
||||
nextPane.hideSpinner();
|
||||
|
||||
if (isDependentSucceeded) {
|
||||
if (exception == null) {
|
||||
lblServerName.setText(serverBeingAdded.getName());
|
||||
lblServerUrl.setText(serverBeingAdded.getUrl());
|
||||
|
||||
|
@ -59,7 +59,7 @@ public final class VanillaInstallWizardProvider implements WizardProvider {
|
||||
if (settings.containsKey("optifine"))
|
||||
builder.version((RemoteVersion) settings.get("optifine"));
|
||||
|
||||
return builder.buildAsync().whenComplete((a, b) -> profile.getRepository().refreshVersions())
|
||||
return builder.buildAsync().whenComplete(any -> profile.getRepository().refreshVersions())
|
||||
.thenRun(Schedulers.javafx(), () -> profile.setSelectedVersion(name));
|
||||
}
|
||||
|
||||
|
@ -128,8 +128,8 @@ public final class VersionsPage extends BorderPane implements WizardPage, Refres
|
||||
@Override
|
||||
public void refresh() {
|
||||
transitionHandler.setContent(spinner, ContainerAnimations.FADE.getAnimationProducer());
|
||||
executor = versionList.refreshAsync(gameVersion, downloadProvider).whenComplete((isDependentSucceeded, exception) -> {
|
||||
if (isDependentSucceeded) {
|
||||
executor = versionList.refreshAsync(gameVersion, downloadProvider).whenComplete(exception -> {
|
||||
if (exception == null) {
|
||||
List<VersionsPageItem> items = loadVersions();
|
||||
|
||||
Platform.runLater(() -> {
|
||||
|
@ -91,9 +91,9 @@ public final class ModListPage extends Control {
|
||||
modManager.refreshMods();
|
||||
return new LinkedList<>(modManager.getMods());
|
||||
}
|
||||
}).whenComplete(Schedulers.javafx(), (list, isDependentSucceeded, exception) -> {
|
||||
}).whenComplete(Schedulers.javafx(), (list, exception) -> {
|
||||
loadingProperty().set(false);
|
||||
if (isDependentSucceeded)
|
||||
if (exception == null)
|
||||
FXUtils.onWeakChangeAndOperate(parentTab.getSelectionModel().selectedItemProperty(), newValue -> {
|
||||
if (newValue != null && newValue.getUserData() == ModListPage.this)
|
||||
itemsProperty().setAll(list.stream().map(ModListPageSkin.ModInfoObject::new).collect(Collectors.toList()));
|
||||
|
@ -51,9 +51,9 @@ public class WorldListPage extends ListPage<WorldListItem> {
|
||||
|
||||
setLoading(true);
|
||||
Task.supplyAsync(() -> World.getWorlds(savesDir).parallel().collect(Collectors.toList()))
|
||||
.whenComplete(Schedulers.javafx(), (result, isDependentSucceeded, exception) -> {
|
||||
.whenComplete(Schedulers.javafx(), (result, exception) -> {
|
||||
setLoading(false);
|
||||
if (isDependentSucceeded)
|
||||
if (exception == null)
|
||||
itemsProperty().setAll(result.stream().map(WorldListItem::new).collect(Collectors.toList()));
|
||||
}).start();
|
||||
}
|
||||
|
@ -68,8 +68,8 @@ public class DefaultGameBuilder extends GameBuilder {
|
||||
libraryTask = libraryTask.thenCompose(dependencyManager.installLibraryAsync(remoteVersion));
|
||||
|
||||
return libraryTask;
|
||||
}).whenComplete((isDependentSucceeded, exception) -> {
|
||||
if (!isDependentSucceeded)
|
||||
}).whenComplete(exception -> {
|
||||
if (exception != null)
|
||||
dependencyManager.getGameRepository().getVersionRoot(name).delete();
|
||||
});
|
||||
}
|
||||
|
@ -19,9 +19,9 @@ package org.jackhuang.hmcl.task;
|
||||
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.jackhuang.hmcl.util.function.ExceptionalRunnable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -29,9 +29,9 @@ import org.jackhuang.hmcl.util.function.ExceptionalRunnable;
|
||||
*/
|
||||
class SchedulerImpl extends Scheduler {
|
||||
|
||||
private final Consumer<Runnable> executor;
|
||||
private final Executor executor;
|
||||
|
||||
public SchedulerImpl(Consumer<Runnable> executor) {
|
||||
public SchedulerImpl(Executor executor) {
|
||||
this.executor = executor;
|
||||
}
|
||||
|
||||
@ -40,7 +40,7 @@ class SchedulerImpl extends Scheduler {
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
AtomicReference<Exception> wrapper = new AtomicReference<>();
|
||||
|
||||
executor.accept(() -> {
|
||||
executor.execute(() -> {
|
||||
try {
|
||||
block.run();
|
||||
} catch (Exception e) {
|
||||
@ -81,7 +81,7 @@ class SchedulerImpl extends Scheduler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
|
||||
public Void get(long timeout, @NotNull TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
|
||||
if (!latch.await(timeout, unit))
|
||||
throw new TimeoutException();
|
||||
return getImpl();
|
||||
|
@ -595,7 +595,10 @@ public abstract class Task<T> {
|
||||
|
||||
@Override
|
||||
public void execute() throws Exception {
|
||||
action.execute(isDependentsSucceeded(), Task.this.getException());
|
||||
if (isDependentsSucceeded() != (Task.this.getException() == null))
|
||||
throw new AssertionError("When dependents succeeded, Task.exception must be nonnull.");
|
||||
|
||||
action.execute(Task.this.getException());
|
||||
|
||||
if (!isDependentsSucceeded()) {
|
||||
setSignificance(TaskSignificance.MINOR);
|
||||
@ -634,7 +637,7 @@ public abstract class Task<T> {
|
||||
* @return the new Task
|
||||
*/
|
||||
public Task<Void> whenComplete(Scheduler scheduler, FinalizedCallbackWithResult<T> action) {
|
||||
return whenComplete(scheduler, ((isDependentSucceeded, exception) -> action.execute(getResult(), isDependentSucceeded, exception)));
|
||||
return whenComplete(scheduler, (exception -> action.execute(getResult(), exception)));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -653,8 +656,8 @@ public abstract class Task<T> {
|
||||
* @return the new Task
|
||||
*/
|
||||
public final <E1 extends Exception, E2 extends Exception> Task<Void> whenComplete(Scheduler scheduler, ExceptionalRunnable<E1> success, ExceptionalConsumer<Exception, E2> failure) {
|
||||
return whenComplete(scheduler, (isDependentSucceeded, exception) -> {
|
||||
if (isDependentSucceeded) {
|
||||
return whenComplete(scheduler, exception -> {
|
||||
if (exception == null) {
|
||||
if (success != null)
|
||||
try {
|
||||
success.run();
|
||||
@ -805,11 +808,11 @@ public abstract class Task<T> {
|
||||
}
|
||||
|
||||
public interface FinalizedCallback {
|
||||
void execute(boolean isDependentSucceeded, Exception exception) throws Exception;
|
||||
void execute(Exception exception) throws Exception;
|
||||
}
|
||||
|
||||
public interface FinalizedCallbackWithResult<T> {
|
||||
void execute(T result, boolean isDependentSucceeded, Exception exception) throws Exception;
|
||||
void execute(T result, Exception exception) throws Exception;
|
||||
}
|
||||
|
||||
private static String getCaller() {
|
||||
|
@ -11,8 +11,8 @@ public class TaskTest {
|
||||
Task.allOf(Task.runAsync(() -> {
|
||||
throw new Exception();
|
||||
}))
|
||||
)).whenComplete(((isDependentSucceeded, exception) -> {
|
||||
Assert.assertFalse(isDependentSucceeded);
|
||||
)).whenComplete((exception -> {
|
||||
Assert.assertFalse(exception == null);
|
||||
})).test();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user