finalized no longer passes AutoTypingMap as callback parameter
This commit is contained in:
@@ -69,7 +69,7 @@ public class DefaultGameBuilder extends GameBuilder {
|
||||
result = result.then(dependencyManager.installLibraryAsync(remoteVersion));
|
||||
|
||||
return result;
|
||||
}).finalized((variables, isDependentsSucceeded, exception) -> {
|
||||
}).finalized((isDependentsSucceeded, exception) -> {
|
||||
if (!isDependentsSucceeded)
|
||||
dependencyManager.getGameRepository().getVersionRoot(name).delete();
|
||||
});
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
* Hello Minecraft! Launcher
|
||||
* Copyright (C) 2019 huangyuhui <huanghongxun2008@126.com> and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.jackhuang.hmcl.task;
|
||||
|
||||
import org.jackhuang.hmcl.util.AutoTypingMap;
|
||||
|
||||
public interface FinalizedCallback {
|
||||
void execute(AutoTypingMap<String> variables, boolean isDependentsSucceeded, Exception exception) throws Exception;
|
||||
}
|
||||
@@ -53,7 +53,7 @@ final class FinalizedTask extends Task {
|
||||
|
||||
@Override
|
||||
public void execute() throws Exception {
|
||||
callback.execute(getVariables(), isDependentsSucceeded(), pred.getLastException());
|
||||
callback.execute(isDependentsSucceeded(), pred.getLastException());
|
||||
|
||||
if (!isDependentsSucceeded())
|
||||
throw new SilentException();
|
||||
|
||||
@@ -320,12 +320,13 @@ public abstract class Task {
|
||||
return new FinalizedTask(this, scheduler, b, ReflectionHelper.getCaller().toString());
|
||||
}
|
||||
|
||||
public final <T extends Exception, K extends Exception> Task finalized(Scheduler scheduler, ExceptionalConsumer<AutoTypingMap<String>, T> success, ExceptionalConsumer<Exception, K> failure) {
|
||||
return finalized(scheduler, (variables, isDependentsSucceeded, exception) -> {
|
||||
// T, K here is necessary, or javac cannot infer type of failure
|
||||
public final <T extends Exception, K extends Exception> Task finalized(Scheduler scheduler, ExceptionalRunnable<T> success, ExceptionalConsumer<Exception, K> failure) {
|
||||
return finalized(scheduler, (isDependentsSucceeded, exception) -> {
|
||||
if (isDependentsSucceeded) {
|
||||
if (success != null)
|
||||
try {
|
||||
success.accept(variables);
|
||||
success.run();
|
||||
} catch (Exception e) {
|
||||
Logging.LOG.log(Level.WARNING, "Failed to execute " + success, e);
|
||||
if (failure != null)
|
||||
@@ -421,4 +422,8 @@ public abstract class Task {
|
||||
SUCCEEDED,
|
||||
FAILED
|
||||
}
|
||||
|
||||
public interface FinalizedCallback {
|
||||
void execute(boolean isDependentsSucceeded, Exception exception) throws Exception;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,14 +55,12 @@ public abstract class TaskResult<V> extends Task {
|
||||
return new Subtask<>(id, scheduler, task);
|
||||
}
|
||||
|
||||
public <T extends Exception, K extends Exception> Task finalizedResult(Scheduler scheduler, ExceptionalConsumer<V, T> success, ExceptionalConsumer<Exception, K> failure) {
|
||||
return finalized(scheduler, variables -> success.accept(getResult()), failure);
|
||||
public <T extends Exception, K extends Exception> Task finalized(Scheduler scheduler, ExceptionalConsumer<V, T> success, ExceptionalConsumer<Exception, K> failure) {
|
||||
return finalized(scheduler, () -> success.accept(getResult()), failure);
|
||||
}
|
||||
|
||||
public Task finalizedResult(Scheduler scheduler, FinalizedCallback<V> callback) {
|
||||
return new FinalizedTask(this, scheduler,
|
||||
(variables, isDependentsSucceeded, exception) -> callback.execute(getResult(), isDependentsSucceeded, exception),
|
||||
ReflectionHelper.getCaller().toString());
|
||||
public Task finalized(Scheduler scheduler, FinalizedCallback<V> callback) {
|
||||
return finalized(scheduler, ((isDependentsSucceeded, exception) -> callback.execute(getResult(), isDependentsSucceeded, exception)));
|
||||
}
|
||||
|
||||
private class Subtask<R> extends TaskResult<R> {
|
||||
|
||||
Reference in New Issue
Block a user