重构 FutureCallback (#5268)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user