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