This commit is contained in:
@@ -46,33 +46,6 @@ public interface AsyncHandler<V, A> extends CompletionHandler<V, A> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建 AsyncHandler 对象
|
|
||||||
*
|
|
||||||
* @param <V> 结果对象的泛型
|
|
||||||
* @param <A> 附件对象的泛型
|
|
||||||
* @param success 成功的回调函数
|
|
||||||
* @param fail 失败的回调函数
|
|
||||||
* @param handler 子回调函数
|
|
||||||
*
|
|
||||||
* @return AsyncHandler
|
|
||||||
*/
|
|
||||||
public static <V, A> AsyncHandler<V, A> create(final BiConsumer<V, A> success, final BiConsumer<Throwable, A> fail, final AsyncHandler<V, A> handler) {
|
|
||||||
return new AsyncHandler<V, A>() {
|
|
||||||
@Override
|
|
||||||
public void completed(V result, A attachment) {
|
|
||||||
if (success != null) success.accept(result, attachment);
|
|
||||||
if (handler != null) handler.completed(result, attachment);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void failed(Throwable exc, A attachment) {
|
|
||||||
if (fail != null) fail.accept(exc, attachment);
|
|
||||||
if (handler != null) handler.failed(exc, attachment);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建没有返回结果的 AsyncHandler 对象
|
* 创建没有返回结果的 AsyncHandler 对象
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user