“分类:Redis”与“Vertx: Future异步操作设计”:页面之间的差异

来自WHY42
(页面间差异)
(建立內容為「<pre> _._ _.-``__ ''-._ _.-`` `…」的新頁面)
 
 
第1行: 第1行:
<pre>
=Future相关操作的设计=
                _._                                                 
== AsyncResult ==
          _.-``__ ''-._                                           
AsyncResult表示一个异步操作的结果,这个结果要么是成功的,要么是失败的。
      _.-``    `.  `_.  ''-._          Redis 2.6.7 (00000000/0) 64 bit
<syntaxhighlight lang="java">
  .-`` .-```.  ```\/   _.,_ ''-._                                 
interface AsyncResult<T> {
(   '      ,       .-`  | `,    )    Running in stand alone mode
    /* 获取异步结果,或者失败原因。倘若失败,那么结果为null */
|`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
    T getResult();
|    `-._  `._    /     _.-'    |     PID: 55757
    Throwable cause();
  `-._    `-._  `-./  _.-'    _.-'                                 
    boolean succeeded();
|`-._`-._    `-.__.-'    _.-'_.-'|                                 
    boolean failed();
|    `-._`-._        _.-'_.-'    |          http://redis.io       
 
  `-._    `-._`-.__.-'_.-'    _.-'                                 
    /* 对结果进行转换。如果成功,那么可以将成功的结果转换为另一种形式;否则可以得到一个替代的结果。*/
|`-._`-._    `-.__.-'    _.-'_.-'|                                 
    <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();
</pre>
}
</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]]

2021年7月25日 (日) 08:21的版本

Future相关操作的设计

AsyncResult

AsyncResult表示一个异步操作的结果,这个结果要么是成功的,要么是失败的。

interface AsyncResult<T> {
    /* 获取异步结果,或者失败原因。倘若失败,那么结果为null */
    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();
}