重构 FutureCallback (#5268)

This commit is contained in:
Glavo
2026-01-23 22:19:43 +08:00
committed by GitHub
parent 65a4b6159d
commit 165d77df30
11 changed files with 81 additions and 64 deletions

View File

@@ -17,18 +17,23 @@
*/
package org.jackhuang.hmcl.util;
import java.util.function.Consumer;
@FunctionalInterface
public interface FutureCallback<T> {
/**
* Callback of future, called after future finishes.
* This callback gives the feedback whether the result of future is acceptable or not,
* if not, giving the reason, and future will be relaunched when necessary.
* @param result result of the future
* @param resolve accept the result
* @param reject reject the result with failure reason
*/
void call(T result, Runnable resolve, Consumer<String> reject);
/// Callback of future, called after future finishes.
/// This callback gives the feedback whether the result of future is acceptable or not,
/// if not, giving the reason, and future will be relaunched when necessary.
///
/// @param result result of the future
/// @param handler handler to accept or reject the result
void call(T result, ResultHandler handler);
interface ResultHandler {
/// Accept the result.
void resolve();
/// Reject the result with given reason.
void reject(String reason);
}
}