Vertx: Future异步操作设计:修订间差异
建立內容為「=Future相关操作的设计= == AsyncResult == AsyncResult表示一个异步操作的结果,这个结果要么是成功的,要么是失败的。 <syntaxhighl…」的新頁面 |
|||
第8行: | 第8行: | ||
boolean succeeded(); | boolean succeeded(); | ||
boolean failed(); | boolean failed(); | ||
AsyncResult<V> map(Function<T, V> mapper); | <V> AsyncResult<V> map(Function<T, V> mapper); | ||
AsyncResult<V> map(V value); | <V> AsyncResult<V> map(V value); | ||
AsyncResult<V> mapEmpty(); | <V> AsyncResult<V> mapEmpty(); | ||
AsyncResult<T> otherwise(T value); | AsyncResult<T> otherwise(T value); | ||
AsyncResult<T> otherwise(Function<Throwable, T> mapper); | AsyncResult<T> otherwise(Function<Throwable, T> mapper); | ||
第17行: | 第17行: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==Future== | |||
Future表示一个尚未完成的异步操作,并继承自AsyncResult | |||
<syntaxhighlight lang="java"> | |||
interface Future<T> | |||
extends AsyncResult<T> { | |||
boolean isComplete(); | |||
Future<T> onComplete(Handler<AsyncResult<T>> handler); | |||
Future<T> onSuccess(Handler<T> handler); | |||
Future<T> onFailure(Handler<Throwable> handler); | |||
<V> Future<V> compose(Function<T, Future<V>> mapper); | |||
<V> Future<V> compose(Function<T, Future<V>> successMapper, | |||
Function<Throwable, Future<V>> failureMapper); | |||
Future<T> recover(Function<Throwable, Future<T>> mapper); | |||
<V> Future<V> transform(Function<AsyncResult<T>, Future<V>> mapper); | |||
<V> Future<T> eventually(Function<Void, Future<V>> mapper); | |||
CompletionStage<T> toCompletionState(); | |||
} | |||
</syntaxhighlight> | |||
[[Category:Vert.x]] | [[Category:Vert.x]] |
2021年7月25日 (日) 08:12的版本
Future相关操作的设计
AsyncResult
AsyncResult表示一个异步操作的结果,这个结果要么是成功的,要么是失败的。
interface AsyncResult<T> {
T getResult();
Throwable cause();
boolean succeeded();
boolean failed();
<V> AsyncResult<V> map(Function<T, V> mapper);
<V> AsyncResult<V> map(V value);
<V> AsyncResult<V> mapEmpty();
AsyncResult<T> otherwise(T value);
AsyncResult<T> otherwise(Function<Throwable, T> mapper);
AsyncResult<T> otherwiseEmpty();
}
Future
Future表示一个尚未完成的异步操作,并继承自AsyncResult
interface Future<T>
extends AsyncResult<T> {
boolean isComplete();
Future<T> onComplete(Handler<AsyncResult<T>> handler);
Future<T> onSuccess(Handler<T> handler);
Future<T> onFailure(Handler<Throwable> handler);
<V> Future<V> compose(Function<T, Future<V>> mapper);
<V> Future<V> compose(Function<T, Future<V>> successMapper,
Function<Throwable, Future<V>> failureMapper);
Future<T> recover(Function<Throwable, Future<T>> mapper);
<V> Future<V> transform(Function<AsyncResult<T>, Future<V>> mapper);
<V> Future<T> eventually(Function<Void, Future<V>> mapper);
CompletionStage<T> toCompletionState();
}